13.07.2015 Views

Beginning CSS: Cascading Style Sheets for Web Design, 2nd ...

Beginning CSS: Cascading Style Sheets for Web Design, 2nd ...

Beginning CSS: Cascading Style Sheets for Web Design, 2nd ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Part I: The Basics}color: green;border: 1px solid green;Just as the direct child selector allows you to apply a style based on a parent/child relationship, next siblingselectors allow you to apply style based on a sibling relationship.Sometimes, it’s useful to have a selector that can apply styles based on the existence or value of an element’sattributes.Attribute SelectorsAttribute selectors are used to apply style sheet declarations based on the presence of attributes orattribute values of an HTML element.IE 6 does not support attribute selectors natively; see this book’s website at www.wrox.com/go/beginning_css2e <strong>for</strong> compatibility help.Figure 3-26 is an example of an attribute selector that applies a style sheet rule based on the presence ofan attribute.Figure 3-26In Figure 3-26, if the alt attribute is set on elements, those elements receive a blue border.Detecting the presence of an alt attribute is good practice, since the alt attribute is required on all elements per the HTML 4.01 specification. When the rule in Figure 3-26 is used, elementsthat don’t have a blue border need an alt attribute applied.You are not limited to detecting the presence of an attribute; there are several types of attribute selectors,and <strong>CSS</strong> is capable of detecting attributes based on the following criteria:❑❑❑❑❑❑The presence of an attributeThe value of an attributeWhether one of several possible values is present in an attributeWhether the attribute value begins with a specific stringWhether the attribute value ends with a specific stringWhether the attribute value contains a specific string anywhere in the value, be it at the beginning,end, or middle82

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

Saved successfully!

Ooh no, something went wrong!