RE: Re[6]: css with attribues [software]

Dmitry Turin wrote:

> <html>
> <style type="text/css">
>   p[color="orange"] {color:green}
> </style>
> <body>
>   <p style="color:orange">Name</p>
> </body>
> </html>
> 
> There is nothing green in Opera.
> If i'm disunderstanding you, correct example above.


No that is not correct. If the html attribute is 'style' then the value for the attribute in an attribute selector must be 'style' and the full string appearing between the "" in the HTML must equal the attributes' value. You have "orange" in your example where this should be "color:orange". Also note that inline styles [1] are more specific [2] than attribute selectors so !important must be used in style declaration for it to work.

1. http://www.w3.org/TR/html401/present/styles.html#adef-style
2. http://www.w3.org/TR/CSS21/cascade.html#specificity


An example:

<html>
<style type="text/css">
  p {color:red}
  [style="color:orange"] {color:green !important}
</style>
<body>
  <p style="color:orange">Name</p>
</body>
</html>


If the html attribute is 'color' then the value for the attribute must be 'color' and it would be like this:

<html>
<style type="text/css">
  p {color:red}
  [color="orange"] {color:green}
</style>
<body>
  <p color="orange">Name</p>
</body>
</html>


Please notice in both examples that I don't even have a 'p' preceding the attribute selector. Your example has.

p[color="orange"]  equals  'type selector'['HTML attribute'="'attributes' value'"]


I am selecting the <p> element by it attribute and value and not by its' type [3]. I could also select all other elements that share the same HTML attribute and value.

3. http://www.w3.org/TR/CSS21/selector.html#type-selectors


Alan

http://css-class.com/

Received on Tuesday, 22 January 2008 15:30:16 UTC