Home arrow HTML arrow Page 5 - W3C Web Standards

W3C Web Standards

The days of “this site is best viewed in...” are over! We shall no longer be discriminated against for using the browser of our choice. Forget tedious template management, and be prepared to save some dollars on bandwidth! The World Wide Web Consortium have come to agreement on the new Web Standards that will allow us to code and maintain our pages with far less effort, all the while resting assured that everyone can see them as we intended.

Author Info:
By: Justin Cook
Rating: 4 stars4 stars4 stars4 stars4 stars / 42
April 12, 2004
  1. · W3C Web Standards
  2. · An Eagle's-Eye View
  3. · First Component: XHTML
  4. · Attributes
  5. · Second Component: CSS2
  6. · Code Explanation
  7. · Third Component: ECMAScript

print this article

W3C Web Standards - Second Component: CSS2
(Page 5 of 7 )

If you're not familiar with CSS level 2, and are hoping that this article will make you a guru, I'm sorry to disappoint you! I will point you to W3C's site for CSS2 (http://www.w3.org/TR/REC-CSS2/) if you want a truly in-depth understanding. But honestly, we just need a few basic concepts to work with here.

You can either use one of your old web pages/templates you may have from a previous project, or you may just wish to start from scratch. For me, I figured that upgrading my site to the new standards was the perfect time to just give it a fresh overhaul. Although, there is a huge advantage in working with an existing page, in that you will get to see with your own eyes that the end result in about 40-60% of the size of the original. Of course, you could just take my word for it!

Basically, let's go with the assumption that all the pages in our site will be based on one template, just to make this tutorial easier. That means that every page will have the aforementioned DTD and XML declaration at the very top of the page. We are going to lay out all of the elements in the page, and then uniquely identify each. Then, within our global style sheet, we will describe the appearance of the elements, and it will all come together in a wonderfully magical way.

Let's assume that we have a few basic elements: a logo, a navigation bar, a title, one main area of content, and a footer. Now I know you've already started to plan out your table, your row and column spans, and a few nested tables, but stop! Our HTML code... oops, sorry, our XHTML code could be as simple as this:

<?xml version="1.0" encoding="UTF-8"? >
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>my standards-compliant page</title>
<div id="logo"><img src="/img/logo.gif" /></div>
<div id="nav">Home Contact me</div>
<h1 id="header">Home Page</h1>
<div id="content" align="center">content</div>
<div id="footer">&copy2004 Acme</div>

The first thing we want to do is assign a default font for our site. Black Chancery might be a bit out there, so let's just stick with our good ol' Arial for now, shall we? And we'll set a few other page attributes while we're at it. So the first few lines of our styles.css could be:

body {
    background-color: #FFFFFF;
    margin: 0px;
    padding: 0px;

Seeing as our cascading style sheet will be cached on the client's browser, these few lines will save us from typing a million <font> tags, or even typing anything whatsoever within our body tags! You could even configure a background image if you're planning to use one. Now let's see what we can do to configure the individual areas of the pages. We'll target each specifically by using the '#' prefix.

#logo {
    padding: 5px 20px 10px 10px;
#nav {
    text-align: right;
    font-weight: bold;
    font-size: 13px;
    background-image:url("/img/navBox.gif") no-repeat top;
#header {
    font-size: 15px;
    margin: 5px;
#content {
    width: 400px; /* more readable paragraphs */
    border: 1px solid #666666;
    padding: 10px;
    text-align: left;
#footer {
    text-align: center;
    font-size: 10px;

blog comments powered by Disqus

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials