我正在try margin-left
个文本的基础上,剪辑路径div,以创建一个交错的外观.目前,我有这样的东西:
#parent {
background-color: red;
clip-path: polygon(10% 0%, 100% 0%, 100% 100%, 0% 100%);
}
#text1 {
margin-left: 10%;
}
#text2 {
margin-left: 7.5%;
}
#text3 {
margin-left: 5%;
}
#text4 {
margin-left: 2.5%;
}
<div id='parent'>
<p id='text1'>Text 1</p>
<p id='text2'>Text 2</p>
<p id='text3'>Text 3</p>
<p id='text4'>Text 4</p>
</div>
However, I want to try to do this more efficiently. I want it so each text doesn't need a separate margin-left
. I'm picturing something where each text is margin-lefting based on the new clipped path edge rather than the original edge of the rectangle:
然后,代码可能如下所示:
<div id='parent'>
<p class='text'>Text 1</p>
<p class='text'>Text 2</p>
<p class='text'>Text 3</p>
<p class='text'>Text 4</p>
</div>
#parent {
background-color: red;
clip-path: polygon(10% 0%, 100% 0%, 100% 100%, 0% 100%);
}
.text {
margin-left: 2%; // Not using exact numbers, but something like this
}
我不确定有没有什么东西可以让我做到这一点,假设是与css相关的.