I use CSS attribute selectors a lot when I write userstyles. I recently tried to write a selector that used the color attribute, but found that it didn't work, regardless of the value I specified or even if I just used the existence test without a value at all. For example, on a page with a p element styled "color: red", none of these CSS snippets affect it:

p[color] { color: blue !important; } p[color="red"] { color: blue !important; } p[color="#f00"] { color: blue !important; } p[color="#ff0000"] { color: blue !important; } p[color="rgb(255, 0, 0)"] { color: blue !important; }

It looks like attribute selectors don't support the color attribute...but I can't find anything in the CSS reference docs that says that. Does anyone know more?

1 answer

1
point
This was chosen as the best answer

The CSS selector attributes are to select HTML attributes.

For example:

span[class="example"]

will target this bit of html:

<span class="example">blah</span>

'class' is a valid HTML attribute, but 'color' is a CSS attribute and can not be used as a part of an attribute selector.

Answered about 6 years ago by Richard Garside
  • *facepalm* duh, right, of course. silly of me. thanks! Ryan B about 6 years ago