나는 구조를 가지고 :n 번째 자식 또는 첫 번째/마지막 자식 선택기가 작동하지 않습니다. 올바른 방법으로 적용하는 방법?
나는 의사 선택기를 사용하여 두 번째li
요소 (클래스 "li_two")에
background:red
을 설정하고 가장 바깥 사업부에서 시작하고자 할
<div id="div">
<ul class="ul">
<li class="li_one">
</li>
<li class="li_two">
</li>
</ul>
</div>
. 나는이 방법을 시도하고있다 :
#div > ul:nth-child(1) { background:red; } // works but wrong, sets background to ul
#div ul:last-child { background:red; } // doesn't set to any element
#div ul:first-child { background:red; } // again sets to ul but not to li
#div [class=li_two] { background:red; } // only this one works fine
그것은 :nth-child
또는 :last-child
또는 :first-child
선택기를 사용하여 #div
에서 li_two
에 스타일을 설정할 수 있습니까? 그것을하는 방법?
, 다음을 선택해야합니다 :'#div> UL> 리 : n 번째 자녀 (1)' –