i want to apply the CSS only first li but :first-child
apply to all first child of every ul
here is my CODE
#menu-navigation li:first-child{
color:red;
}
When applied to this HTML:
<ul class="nav" id="menu-navigation">
<li>Home</li>
<li>About Us
<ul>
<li>Our Team</li>
</ul>
</li>
</ul>
...both "Home" and "Our Team" turn red.
The :first-of-type selector in CSS allows you to target the first occurence of an element within its container. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.
The :first-of-type CSS pseudo-class represents the first element of its type among a group of sibling elements.
CSS ::first-line Selector The ::first-line selector is used to add a style to the first line of the specified selector. Note: The following properties can be used with ::first-line: font properties. color properties.
The trick is very easy, in CSS we have the sibling selector ("+"), if i will make selector that choose "li + li" it will select all list-items except the first . That's all!
use the child selector:
#menu-navigation>li:first-child{
color:red;
}
For example: http://jsfiddle.net/w47LD/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With