Skip to Navigation or
Skip to Content

CSS Wish List

Feeds

RSS Feed

<< August | September | October >>

Saturday, 13th September 2008

This is a quick one really!

What I'd really like are some inverse selectors in CSS, which would allow me to select a parent element where a child element matches my criteria.

Existing child selectors include these three handy chaps (information from W3C):

E > F - Matches any F element that is a child of an element E.
E + F - Matches any F element immediately preceded by an element E.

I reckon it would be incredibly useful to perform the following selections:

E < F - Matches any F element that is a parent of an element E.
E - F - Matches any F element immediately followed by an element E.

My real life example is the following...

It's considered best-practice by many people to avoid using underlines for hyperlinks. They cut across hanging letters such as g, q and p (g, q and p), which makes them less readable. The alternative is to use a border along the bottom, which appears below the hanging letters.

To achieve this, you simply set the following CSS:

border-bottom: 1px solid blue;

This works great - until you have a hyperlinked image. Typically, you wouldn't want the border to appear on the image. You've set it against the text to make it more readable, but it has no use on the image. Using the CSS inverted selector you could set the following rule:

img < a { border-bottom: none; }

And the border would only appear for the text. Job done!

 

You Are Here: Home » Blog » CSS Wish List

 

I use a cookie on this website. This cookie doesn't contain or relate to any personal information and it isn't shared with any other website, it just ensures that I don't count you more than once in my website statistics. The Privacy and Electronic Communications Regulations require me to ask your permission to use this cookie, so please indicate below that you are happy for me to do this - I will remember your selection with a cookie, so if you accept I won't ask again...