答案 0 :(得分:5)
使用绝对定位的伪元素来实现相同的目的。在下面的示例中,我使用的是::before
绝对定位并设置为父级的完整高度(使用top: 0; bottom: 0;
技巧)。然后,您可以简单地设置宽度并使用宽度的一半的border-radius
来实现圆角。
p {
position: relative; /* Required so that pseudo-element is positioned correctly */
padding-left: 30px; /* Dummy value to make space for pseudo-element */
}
p::before {
/* Create pseudo-element and give it content */
content: '';
display: block;
/* Position it in its parent so that it is:
* - to the left
* - occupies full height
*/
position: absolute;
top: 0;
left: 0;
bottom: 0;
/* Give it a fixed width and rounded corners */
width: 10px;
border-radius: 5px;
/* Appearance */
background-color: steelblue;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sollicitudin metus tincidunt felis maximus, maximus sollicitudin mi ultrices. Curabitur libero arcu, bibendum ac suscipit ut, elementum scelerisque lacus. Praesent ultricies commodo porttitor. Fusce eget velit nisi. Praesent vulputate venenatis dui, efficitur sollicitudin nisi pulvinar a.</p>
答案 1 :(得分:1)
试试这个:
.txt {
width: 400px;
position: relative;
}
.txt:before {
content: '';
width: 10px;
height: 100%;
position: absolute;
background-color: skyblue;
border-radius: 5px;
}
p {
margin-left: 20px;
}
&#13;
<div class="txt">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sollicitudin metus tincidunt felis maximus, maximus sollicitudin mi ultrices. Curabitur libero arcu, bibendum ac suscipit ut, elementum scelerisque lacus. Praesent ultricies commodo porttitor. Fusce eget velit nisi. Praesent vulputate venenatis dui, efficitur sollicitudin nisi pulvinar.
</p>
</div>
&#13;