我有一个容器,里面有一堆div。我想要一个灰色的上边框,除了第一个应该是白色的上边框。我尝试了第n个子代,但我的代码中似乎有问题。
<div class="container">
<div class="row"> Stuff </div>
<div class="row"> Stuff </div>
<div class="row"> Stuff </div>
<div class="row"> Stuff </div>
</div>
.row{ border-top-width: 1px; border-top-style: solid; border-top-color: #ccc;}
.row:nth-child1{ border-top-width: 1px; border-top-style: solid; border-top-color: #FFF;}
发布于 2013-03-06 02:49:23
.row { border-top: 1px solid #ccc;}
.row:first-child { border-top-color: #FFF;}
jsFiddle:http://jsfiddle.net/MSDYY/
另一个,背景设置为红色,以显示在第一个元素上实际上有白色的顶部边框:http://jsfiddle.net/MSDYY/1/
如果你想使用nth-child
,它应该是这样的:.row:nth-child(1)
发布于 2013-03-06 02:50:58
使用以下两种方法:
.row:nth-child(1)
或
.row:first-of-type
或
.row:first-child
前两个是IE9+,但最后一个也可以在IE8中使用。
https://stackoverflow.com/questions/15231684
复制相似问题