Reputation: 12998
I have the following css which needs to alter the last-child which does not have the class "myClass" but I can't seem to get it to work.
Any ideas where I'm going wrong?
ul li:not(.myClass):last-child a {
font-style:italic;
}
Example html as requested:
<ul>
<li><a href="#">one</a></li>
<li><a href="#">two</a></li>
<li><a href="#">three</a></li>
<li class="myClass"><a href="#">Extra</a></li>
</ul>
I want to apply the css to li three...
Upvotes: 4
Views: 411
Reputation: 9469
Try something like this:
ul li:not(.myClass):nth-last-of-type(2) a {
border-right:0px solid #000;
}
Upvotes: 0
Reputation: 2233
this can't be done with css only if you are capable to use jQuery you might find this solution helpful.
$('ul li').not('.myClass').last().find('a').addClass('mystyle');
Upvotes: 2
Reputation:
Current CSS syntax is not capable of facilating an AND
operator to perform this kind of style. What you need is the CSS LESS Framework.
This will allow you to do this:
ul > li:not(.myClass) {
li:last-child {
//style here
}
}
Upvotes: 0
Reputation: 21114
If you're sure the element you want to target is the last but one, you can use nth-last-child(2)
ul li:nth-last-child(2) a {
border-right:0px solid #000;
}
Upvotes: 1
Reputation: 14205
If you want to apply the css only to li three, Try :nth-child(3)
ul li:nth-child(3) a {
border-right:0
}
This pseudo-class matches elements on the basis of their positions within a parent element’s list of child elements. – http://reference.sitepoint.com/css/pseudoclass-nthchild
Upvotes: 0