HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

Chapter 34


Untangling HTML and Style


Contents


34.1 Rules and Exceptions................ 289
34.2 The Cascade..................... 289
34.3 Specificity....................... 290

In some of our examples we placedstyle="..."directly into the HTML of
the webpage.


This is called in-line styling.


It is usually considered to be a bad thing. Why so?


For uniformity and consistency, we generally like to apply one style across
our entire webpage or website. When we embed the styling commands
directly into the content, it makes it very difficult to stay consistent.


Ideally we want to specify all our styling commands in one place, and then
have them apply throughout our website.


So, avoid in-line styling.


In an ideal world, we would put as little styling into the HTML as possible.
That is because it makes things more complicated.


Why untangle? Writing content (HTML) is a skill. Styling content (CSS) is
a skill. It is easier to find two persons who enjoy and are each expert in one
area than it is to find one person who enjoys and is expert in both areas.


(We run into a similar problem when we use JavaScript likeonclick="..."


288

Free download pdf