CSS/Selectors/attribute selector/attributel=value

From W3C Wiki
< CSS‎ | Selectors
Revision as of 19:04, 26 September 2011 by Hiroki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

[attributename|="val"]

This selector represents an element with the "attributename" attribute, its value either being exactly "val" or beginning with "val" immediately followed by "-".

Syntax

elementname[attributename|="val"]{ properties }


Point, Note

  • This is primarily intended to allow language subcode matches.


Example

The following selector represents an a element for which the value of the hreflang attribute begins with "en", including "en", "en-US", and "en-scouse":

[style.css]

 a[hreflang|="en"]{
   font-style: italic;
 }

[index.html]

<body>
  <p><a href="http://www.w3.org/" hreflang="en-US">W3C</a> is an international community</p>
</body>

Css3 selectors att 004.png

CSS defines the attribute selector in 6.3.1. Attribute presence and value selectors.