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 Basicsrules to be applied to as many documents as the author wishes. This is one of the key benefits of <strong>CSS</strong>baseddesign. An external style sheet offers flexibility to the author that saves both time and resources.Importing <strong>Style</strong> <strong>Sheets</strong>You can also link to an external style sheet by using the @import rule. Here’s a demonstration:@import url(path/to/cssdoc.css);This example uses the method but includes the @import notation. It’s very straight<strong>for</strong>ward:Plug in the @import rule followed by the url(), which may contain an absolute or relative path.The @import method is not supported by older browsers, and it is sometimes used as a hack to hidestyles from browsers that would crash horribly if these styles were present. One such browser isNetscape Navigator 4, which has horrible <strong>CSS</strong> support and has been known to lock up when certainstyles are present.The next section describes how styles can be included inline, directly on elements, by using the styleattribute.Inline <strong>Style</strong>sThe last method <strong>for</strong> including <strong>CSS</strong> in a document is from within the XHTML elements themselves.Sometimes it doesn’t make sense to clutter your external or embedded style sheets with a rule that willbe used on only one element in one document. This is where the style=”” attribute comes into play; it’sdemonstrated by the following markup:Some text aligned left.This method allows <strong>for</strong> the text to be <strong>for</strong>matted from within the document and may be applied to anyrendered element.The following Try It Out demonstrates how the style attribute is used to add styles directly to the elementsof a web document.Try It OutIncluding <strong>CSS</strong> Using the style AttributeExample 2-10. To use the style attribute to apply styles directly to the elements of a document, followthese steps.56

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

Saved successfully!

Ooh no, something went wrong!