Navigation |
An example of separation of content and design.A web site had quotes inserted in different pages, used as an opening to several articles. Here is one such quote (and how it was presented): “The remedy for what ails our democracy is not simply better education (as important as that is) or civic education (as important as that can be), but the reestablishment of a genuine democratic discourse in which individuals can participate in a meaningful way – a conversation of democracy in which meritorious ideas and opinions from individuals do, in fact, evoke a meaningful response.” Al Gore, The Assault on Reason With the authorization of the webmaster, here is the page used as example. Here is the code the webmaster used to present the quote: <p><strong>“The remedy for what ails our democracy is not simply better education (as important as that is) or civic education (as important as that can be), but the reestablishment of a genuine democratic discourse in which individuals can participate in a meaningful way – a conversation of democracy in which meritorious ideas and opinions from individuals do, in fact, evoke a meaningful response.”</strong></p>There are two problems with this code:
Can you find them? Using valid HTML markupThe validation problem is here: <p align=right><strong>Al Gore</strong></p>The validator complains that there is no attribute "align" for the element The quick and dirty solution is to use in-line CSS (i.e. css declared within an HTML element, as an attribute). The result would be: <p style="text-align: right;"><strong>Al Gore</strong></p>Despite being correct (it will validate), this code is less than ideal. See below to know why. Why bother?The thing is most, if not all, browsers will properly handle improper HTML. Both the "improper" HTML and the "correct" one are presented exactly the same within the browser. To understand why it is style a good idea to code valid HTML, one has to go to the philosophy that inspired the creation of CSS in the first place. Here is not the place to reproduce the whole justification. Let's just say that the style of a web site can change anytime by just applying a single style sheet. That style sheet will affect ALL the content on the site, including pages created years earlier. The HTML code however will stay the same. If changes in the HTML of the page content must be made, each single page must be updated individually by hand, one by one. In the example above, suppose we decide one day to change the presentation of the quotes. If the presentation is hard coded within the HTML, each of the pages containing a quote must be manually changed one by one, so that we have a consistent look throughout the site. On the other hand, if a proper semantic HTML markup has been used and the styling definition relegated to a CSS file, then changing the styling of the quotes throughout the web site is only a matter of changing one CSS file. This is the reason why the following code, although valid, is the wrong approach: <p style="text-align: right;"><strong>Al Gore</strong></p>Here the CSS code is embedded within the HTML, and to change the styling, one still would have to change each individual page to make it consistent in every page. What's the second problem then?Now that you have read so far, can you guess what is the second problem that I mentioned above? Read again the beginning and try to guess before reading below. Have you guessed? The problem is both with the use of the elements It's a minor point, but I guess that The use of The problem here is the webmaster's logic: instead of thinking in terms of content ("What is the semantic value of what I am typing?"), he's thinking in terms of presentation ("I want this to look bold. How do I achieve that?"). The proper approach would be to use the HTML to properly describe the semantic nature of the text, and then use CSS to make it look the way we want. This is a long term investment: the HTML code won't decay and can remain the same, but the presentation can be adjusted across the site at any time by modifying a single CSS file. A solutionNotice that it is not the solution: there are different ways to code the quote. So, here is a solution: <blockquote class="quote"><p>“The remedy for what ails our democracy is not simply better education (as important as that is) or civic education (as important as that can be), but the reestablishment of a genuine democratic discourse in which individuals can participate in a meaningful way – a conversation of democracy in which meritorious ideas and opinions from individuals do, in fact, evoke a meaningful response.”</p>Here, we wrap the whole thing (the actual quote AND the author) in a The name of the author is placed in a paragraph on its own, with a proper class identification (naturally: "author"). Note that we don't use the element Note also that we don't make use of inline CSS declaration anymore. By keeping the CSS (below) in its own file, it is easier to change anytime without editing each single page. Inline CSS declaration is useful when we want to make a one-off exception on how the text is presented. E.g. above: I needed to make an extra high blank space between two paragraphs to signify to the readers that I expected them (you!) to actually go back to the beginning of the article and take a second guess at what the second problem was. <p style="margin-top: 10em; margin-bottom: 10em;">Have you guessed?</p>To conclude our solution, we need to add the following code to the CSS file : blockquote.quote {Thus we get valid HTML and a CSS-based presentation that can be changed any time. By augustin at 2007-08-20 13:53 | English
|
Pacte Écologiqueweb design |