W3C home > Mailing lists > Public > www-style@w3.org > September 2010

Re: CSS selector - Select parent element (li) if child element (a) has an attribute of href="#"

From: Eduard Pascual <herenvardo@gmail.com>
Date: Sun, 12 Sep 2010 02:16:27 +0200
Message-ID: <AANLkTinagKTm6_yArdqUu9=7-Yt76qJV-G++ELKBk722@mail.gmail.com>
To: Matthew Millar <mattmill30@hotmail.com>
Cc: www-style@w3.org
On Sun, Sep 12, 2010 at 2:03 AM, Matthew Millar <mattmill30@hotmail.com> wrote:
> Hi,
>
> I'm trying to streamline my code and I've found a few areas where i'm
> defining classes etc, where I can probably get away with using CSS logic.
>
> However, i'm stuck on how to give a parent element certain css styles if its
> child element has a particular attribute.

A lot of variations on features that would handle that have been
proposed; but Selectors 3 didn't include any mostly because they all
present serious implementation issues/challenges. It was included,
however, in the list of things to try to address on Selectors 4.

On the meanwhile, you may consider using the JQuery library and its
:has() pseudo-class; or stick to classes; whichever works better for
your case. It will definitely take a while to get this feature
implemented in an interoperable and reliable way.

Regards,
Eduard Pascual

> Example:
>
> <ol>
>    <li><a href="somewhere.html">Somewhere Else</a></li>
>    <li><a href="#">Current Page</a></li>
> </ol>
>
> I want to apply a background-color to the li with a child anchor element who
> has the attribute href="#".
>
> I noticed on CSS 3 selectors and undefined (Blank) :contains selector and
> i'm not sure if this is what i'm looking for.
>
> http://www.w3.org/TR/css3-selectors/#content-selectors
>
> Thanks in advance for any help,
>
> Matthew Millar
>
Received on Sunday, 12 September 2010 00:17:21 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:31 GMT