12.09.2015 Views

Boot Camp

Web Authoring Boot Camp - StudioBast

Web Authoring Boot Camp - StudioBast

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Styling Code, Part 2<br />

• Styles can apply to elements nested in a particular way. You can define styles to<br />

apply to particular kinds of elements nested within (or a child of) other particular<br />

kinds of elements. These would only affect the nested items, not other selectors of<br />

the same name elsewhere in the page.<br />

Note: Inheritance can get to be a little too much fun and this makes CSS sometimes experimental<br />

in nature. In other words, you may find you have to do detective work to track<br />

down which style you create that is adversely affecting another style you are building.<br />

You’ll learn a lot more by trial and error, but here are the basics:<br />

• Inheritance: when all descending styles inherit the style of a parent, like table cells<br />

inheriting a align:left from the table selector<br />

• Specificity: when you specifically tell an inherited style to do something different:<br />

table {align:left;} td {align:center;}<br />

• Location: This rule breaks a tie when inheritance and specificity are duking it out.<br />

Rules that appear later have more weight (such as if you apply a style right inside<br />

your XHTML code.<br />

• Override: You can also override the whole style system you create by declaring<br />

that a particular rule is more important than all the others: td {align:center !important;}<br />

• Comment: Use CSS commenting to clearly note what you are doing, and why.<br />

This makes it easier for you to keep track of what styles might be the parent styles<br />

that a problem style is inheriting something from.<br />

The Important Keyword<br />

The important keyword makes a declaration take precedence over normal declarations, or<br />

those that are not styled with the important keyword. So “p {color: #000 ! important;}”<br />

takes precedence over “p {color: #ccc;}”. The syntax for an important declaration is<br />

property: value ! important;<br />

The relative importance of a rule also depends on its the source: whether it comes from a<br />

style sheet specified by the document author, the user or the user agent (browser). The order<br />

of declarations from least important to most important:<br />

• User agent declarations<br />

• User normal declarations<br />

• Author normal declarations<br />

213

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

Saved successfully!

Ooh no, something went wrong!