1

I'm trying to find a CSS selector that can help me distinguish between the <var> tags in these 2 different usages:

<p><var>Foo</var></p>

And

<p>Some text <var>Foo</var> and more text</p>

Basically if a var has a sibling that is a text node I need to style it differently. Suggestions?

2
  • No, I don't need to support IE6.
    – mpeters
    Commented Mar 3, 2010 at 21:11
  • 1
    There is no such CSS selector alone that can do this. You will have to detect such elements with JavaScript. Commented Mar 3, 2010 at 21:23

1 Answer 1

1

This is not possible, sorry. Check out that discussion: http://forum.userstyles.org/comments.php?DiscussionID=6 or the official W3C pages http://www.w3.org/TR/css3-selectors/ where you can see that even CSS3 will not support this. The only way CSS even considers the DOM text nodes is the :empty pseudo class selecting elements that are empty, i.e. do not have children neither text nodes.

Not the answer you're looking for? Browse other questions tagged or ask your own question.