I am trying to prevent the hover and focus effect only on first row, but when I am applying "first-child" pseudo code it applies to all the rows.. Here's the code:
/* CSS */
ul {list-style-type: none;}
ul > li > a {
background: transparent;
font: normal 12px Arial, sans-serif;
color: #007DBD;
margin: 0;
border-radius: 0;
padding: 7px 10px;
width:200px;
}
ul > li > a:first-child {
color:#333;
background: none;
}
ul > li > a:hover, ul > li > a:focus {
color: #009BE1;
background: #F3F3F3;
text-decoration: none;
}
/* HTML */
<ul>
<li><a href="javascript:;">[email protected]</a></li>
<li><a href="javascript:;">Edit Profile</a></li>
<li><a href="javascript:;">Logout</a></li>
</ul>
I don't want any hover effect for first <li><a> item.
Here's the js-fiddler:
http://jsfiddle.net/123qyrtc/
Please let me know if there is any CSS solution...
ul > li:first-child > a:hover, ul > li:first-child > a:focus {
color:#333;
background: none;
text-decoration:underline
}
Use the :not() pseudo to exclude what you don't want:
Updated JsFiddle
ul > li:not(:first-child) > a:hover, ul > li > a:focus {
color: #009BE1;
background: #F3F3F3;
text-decoration: none;
}
Just remember that the :first-child in this case is the <li>, not the a. The a is always first.
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