CSS/Selectors/attribute selector/attribute

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

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

[attributename]

This selector represents an element with a "attributename" attribute, whatever the value of the attribute.

Syntax

elementname[attributename]{ properties }

Example

The following attribute selector represents an p element that carries the title attribute, whatever its value:

[style.css]

 p[title]{
   color: red;
   font-size: 1.2em;
 }

[index.html]

<body>
  <p title="sample text">This is a paragraph.(with title attribute)</p>
  <p>This is a paragraph.</p>
</body>

Css3 selectors att 001.png

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