[英]Problem with selecting a nested last element
I have this HTML code with applied CSS. 我有应用CSS的HTML代码。
I need all div with cnt-list-box
in red but ONLY the LAST div cnt-list-box
with different color. 我需要所有带有红色的cnt-list-box
div,但只有最后一个具有不同颜色的div cnt-list-box
。 Any ideas? 有任何想法吗?
<div class="cnt-box-1">
<div class="cnt-list-box">content 1</div>
<div class="cnt-list-box">content 2</div>
<div class="cnt-list-box">content 3</div>
<div class="cnt-list-box">content 4</div>
<div class="cnt-list-box">content 5</div>
</div>
.cnt-list-box
{
background-color:Red;
}
your example does work in FF and Webkit: http://jsfiddle.net/meo/hwFYT/ 您的示例在FF和Webkit中确实有效: http : //jsfiddle.net/meo/hwFYT/
As commented by usoban you should check: Changing CSS for last <li> 正如usoban所评论的,您应该检查: 更改最后一个<li>的CSS
PS: your incode comment is not a valid CSS comment. PS:您的incode注释不是有效的CSS注释。 It produces a parsing error this is why it seams to work, but its no a good practice. 它产生一个解析错误,这就是为什么它可以正常工作的原因,但是这不是一个好习惯。
Fortunately I found by myself a reasonable solution to my problem. 幸运的是,我自己找到了解决问题的合理方法。
.cnt-box-1 > .cnt-list-box:last-child
{
background-color: Blue;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.