是否可以将:: before和:: after元素添加到列表项?
例如,如果我有以下内容:
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
我可以定位最后一个项目,比如说添加一个:: after元素,还是只能定位实际的UL元素?
ul li:nth-child(3)::after
{
content: "";
height: 10px;
width: 10px;
background: transparent;
border: 1px solid #ccc;
}
是的,您可以使用,请确保将position:absolute设置为您的伪元素的高度和宽度。
ul li:nth-child(3)::after {
display block;
position: absolute;
content: "";
height: 10px;
width: 10px;
background: transparent;
border: 1px solid #ccc;
}
<ul>
<li>One</li>
<li>Two</li>
<li>Three3</li>
</ul>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句