No, this would not be possible with pure CSS since there is currently no parent selector.
You could, however, use the following work-around. Just style all the .links
elements. Then just reset the styling by selecting .links
elements that are children of p
elements.
.links {
background-color:#ccc;
}
p > .links {
background-color:transparent;
}
As an alternative, you could also use the following. It's worth noting that this method will only work with your current HTML. (example)
p ~ a.links {
background-color:#ccc;
}
If you want a jQuery solution, you could use the following. It will select all a
elements that are not children of p
elements.
$('a:not(p a)').css('background','#ccc');