Is there a CSS selector to target elements with inline styles? So can I target the first span but not the 2nd with CSS only?
If not, can this be done with jQuery?
http://jsfiddle.net/TYCNE/
<p style="text-align: center;"> <span>target</span> </p> <p> <span>not target</span> </p>
Inline Style Syntax In our case, the value of the style attribute will be CSS property-value pairs: "property: value;" . You can have as many property value pairs as you want. Unlike normal CSS syntax, inline styling does not use selectors or curly braces.
The CSS Attribute Selector is used to select an element with some specific attribute or attribute value. It is an excellent way to style the HTML elements by grouping them based on some specific attributes and the attribute selector will select those elements with similar attributes.
The [attribute|="value"] selector is used to select elements with the specified attribute, whose value can be exactly the specified value, or the specified value followed by a hyphen (-). Note: The value has to be a whole word, either alone, like class="top", or followed by a hyphen( - ), like class="top-text".
The :link selector is used to select unvisited links.
A bit late to the tea party but thought I would share the solution I found & use.
@simone's answer is perfect if you can match the style attribute exactly. However, if you need to target an inline style attribute that may have other inline styles associated with it you can use:
p[style*="text-align:center;"]
"*=" means "match the following value anywhere in the attribute value."
For further reference or more detailed information on other selectors see this blog post on css-tricks.com:
The Skinny On CSS Selectors
http://css-tricks.com/attribute-selectors/#rel-anywhere
p[style="text-align: center;"] { color: red; }
However this is ugly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With