24.08.2016 Views

HTML and CSS design and build websites

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Attribute Selectors<br />

You met the most popular <strong>CSS</strong> selectors on page 238. There are also<br />

a set of attribute selectors that allow you to create rules that apply to<br />

elements that have an attribute with a specific value.<br />

Selector Meaning Example<br />

Existence<br />

Equality<br />

Space<br />

[]<br />

Matches a specific attribute<br />

(whatever its value)<br />

[=]<br />

Matches a specific attribute with<br />

a specific value<br />

[~=]<br />

Matches a specific attribute<br />

whose value appears in a spaceseparated<br />

list of words<br />

p[class]<br />

Targets any element with an<br />

attribute called class<br />

p[class="dog"]<br />

Targets any element with<br />

an attribute called class whose<br />

value is dog<br />

p[class~="dog"]<br />

Targets any element with<br />

an attribute called class whose<br />

value is a list of space-separated<br />

words, one of which is dog<br />

Prefix<br />

SubString<br />

Suffix<br />

[^=]<br />

Matches a specific attribute<br />

whose value begins with a<br />

specific string<br />

[*=]<br />

Matches a specific attribute<br />

whose value contains a specific<br />

substring<br />

[$=]<br />

Matches a specific attribute<br />

whose value ends with a specific<br />

string<br />

p[attr^"d"]<br />

Targets any element with<br />

an attribute whose value begins<br />

with the letter "d"<br />

p[attr*"do"]<br />

Targets any element with an<br />

attribute whose value contains<br />

the letters "do"<br />

p[attr$"g"]<br />

Targets any element with an<br />

attribute whose value ends with<br />

the letter "g"<br />

TEXT<br />

292

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!