Is it possible to select an element with certain style using CSS?
Like... all img that has style="position:fixed;"
What I mean is - selecting elements depending on their style instead of class or id.
Is it possible to select an element with certain style using CSS?
Like... all img that has style="position:fixed;"
What I mean is - selecting elements depending on their style instead of class or id.
I'd actually use that one:
[style~="position:fixed;"]{
/* whatever */
}
See the explanation here
so it'll catch all elements that have position:fixed;
in their style (because they may have other styles attributes as well)
But if that position
attribute is not written in the HTML, the selector will not select them. you will have to use JQuery for that. Read here
You can use
div[style="position:fixed;"] {
color:red;
}
to select all elements like this
<div style="position:fixed;">
</div>
But be careful, you have to take the statement style="position:fixed;"
exactly that way into your selector. Even if you omit the ;
or add a blank space (position: fixed
) it won't lead to your desired result anymore.
You can use the attribute selector:
[style="position:fixed;"]{
/* whatever */
}
Here's a demo: http://codepen.io/anon/pen/EvfDi
If you want to select each element with a style='position:anything', I would take a look at the w3c spec on css3 attribute selectors: http://www.w3.org/TR/css3-selectors/#attribute-selectors