css - how to select the element in a tree structure? -
codepen: http://codepen.io/singlexyz/pen/emqyeb
html:
<div class="item"> <a href="">首页</a> <div class="item"> <a href="">项目</a> <div class="item"> <a href="">招贤</a> <div class="item"> <a href="">联系</a> </div> </div> </div> </div>
scss
.item{ background-color:skyblue; @for $i 1 through 4{ &:nth-child(#{$i}){ margin-left:$i * 10px; } } }
the nth-child(3) doesn't select that.
i try use nth-of-type, it's take nth-of-type(1).
have need add class in every .item ?
the correct way use space since talking children , not siblings
div div div {}
div div div{ background: red }
<div class="item"> <a href="">首页</a> <div class="item"> <a href="">项目</a> <div class="item"> <a href="">招贤</a> <div class="item"> <a href="">联系</a> </div> </div> </div> </div>
to use nth-child have change markup structure
div:nth-child(3){ background: red }
<div class="item"> <a href="">首页</a> </div> <div class="item"> <a href="">项目</a> </div> <div class="item"> <a href="">招贤</a> </div> <div class="item"> <a href="">联系</a> </div>
Comments
Post a Comment