Reputation: 4909
I have css code like this
<ul class="simple-list">
<li>
<ul>
<li>Paper</li>
<li>Pen</li>
</ul>
</li>
<li>
<ul>
<li>Paper</li>
<li>Pencil</li>
</ul>
</li>
</ul>
Now when I use style like this
.simple-list li {
border-bottom: 1px solid #EEE;
display: block;
}
It affects all child li elements too. Can someone tell me how to make it affect only the first li element. ?
Upvotes: 2
Views: 804
Reputation: 9648
Do you mean only the immediate li children of .simple-list (i.e the first level)? or just the first one? If it's immediate children only you want
.simple-list > li
For just the first one you want @Steve Fenton's answer above
Upvotes: 2
Reputation: 251242
Like this:
.simple-list li:first-child {
You can check support for first-child on caniuse.com
Upvotes: 3