HTML and CSS Reference
In-Depth Information
HTML style Attribute
HTML content elements (those not associated with the document
<head> ) have a style attribute that can be used to assign a semicolon-
separated list of CSS declarations to that specific element.
<p style=”color: pink”>A Pink Paragraph</p>
This attribute is an unwieldy method of styling an entire document but
can occasionally be useful on a project where it is important for style
information to be matched with the HTML content such as when sharing
HTML content across sites or defining one-off special cases for styling an
element.
JavaScript and the DOM
JavaScript can access style sheets and style properties via the Document
Object Model (DOM). JavaScript can be used to set styles via the style
object on an element or to read current styling information (used values)
via the getComputedStyle method.
You can also use JavaScript to read the contents of style sheets via the
document.styleSheets object, which is a useful technique for creating
bridge libraries to bring support for unsupported CSS properties or selec-
tors to older browsers (discussed in Chapter 13).
note Multiword CSS properties when accessed though JavaScript are camel
cased, rather than hyphenated. In other words, margin-left becomes
marginLeft .
Coding Styles
CSS does not rely on whitespace or indentation to parse the values, but
consistent use of whitespace can make code easier to follow—as can
thoughtful organization of the rules in a document and good use of CSS
 
 
Search WWH ::




Custom Search