I have following html markup. I want to apply a css style to the li
items which are direct children of main ul
. I do not want to select the li items which are nested inside li
. How can I do that?
In the following code, I want to select only "main item 1" and "main item 2". I'm trying > operator but it does not work.
HTML:
<div class="nav">
<ul>
<li><a>Main item 1</a></li>
<li><a>Main item 2</a>
<ul>
<li><a>sub item 1</a></li>
<li><a>sub item 2</a></li>
</ul>
</li>
</ul>
</div>
CSS:
.nav > ul li a:hover{
color: red;
}