HTMLGoodies
The ultimate html resource
Earthweb.com


About the Double-Underlined Links



Search Clipart.com:



internet.commerce
Prepaid Phone Card
Phone Cards
Disney World Tickets
Imprinted Gifts
GPS Devices
PDA Phones & Cases
Laptop Batteries
Promotional Products
Rackmount LCD Monitor
Best Price
KVM over IP
Boat Donations
Data Center Solutions
Corporate Awards

HTML Goodies : Beyond HTML : Cascading Style Sheets: CSS Layouts Without Tables

HTML GOODIES TO GO NEWSLETTER


Other Related Newsletters

Verisign Whitepaper: Maximizing Site Visitor Trust Using Extended Validation SSL. Increase confidence on your site and see more conversions. Learn how by downloading this whitepaper.

CSS Layouts Without Tables


By Jon Jackson

Cascading Style Sheets (CSS) are the most flexible way to create attractive, standards-compliant websites. Even so, many web designers choose to stick to the original HTML elements that they are familiar with in order to implement their designs. For example, HTML tables are often used in order to create the seemingly complex layouts on some web pages.

This article will simply address the drawbacks of relying too heavily on tables for layout as well as the benefits of CSS. It will also demonstrate how to implement a couple of page layouts using HTML and CSS as an alternative to HTML tables.

A Shift Towards Semantic Mark-up

If we look to the World Wide Web Consortium (W3C) for guidelines on how to use HTML properly, the use of semantic mark-up is always strongly recommended. This means that code should be meaningful as well as syntactically correct.

Well formed semantic mark-up offers greater accessibility to users on various platforms (such as mobile devices) and allows for greater flexibility, scalability and performance of your Website and its pages. This is one of the main driving forces behind XHTML.

An example of poor semantic mark-up would be using the following code to represent a sub-heading on an HTML page:

	<p><b>Heading</b></p>
Syntactically this is correct. Semantically though, it is a little off the mark. This code represents a paragraph which is in bold type; not a heading. To represent a heading or sub-heading in HTML we can use the heading tags (<h1>, <h2>, <h3> etc...) to surround the heading text.

Relating this idea to HTML tables would mean that tables should only be used for tabular data and not for layouts and positioning. But how can we create a decent page layout without tables? Surely everything will just appear in a single boring column if we don't use tables...

CSS to the Rescue!

In the introduction to this article we said that CSS enables us to create attractive websites. A quick glance at http://www.cssremix.com certainly gives some weight to this argument. Now let's look at how we can actually implement some different page layouts.

For these examples we are going to use XHTML 1.0 Strict along with an embedded CSS style block. In practice this CSS can be included in a separate .css file (for details on how to do this please refer to this page). The full XHTML and CSS code for each layout can be copied into a single text file and named with the .html extension.

It doesn't matter whether you use HTML or XHTML as your document type, as long as your mark-up is nice and clean. Validating your code using the W3C validation tools is always a good idea.

3 Column Layout With Header and Footer

The 3 column layout is common these days. The following HTML and CSS enables you to create a flexible 3 column layout with the minimum of fuss. You can see this page layout here.

We'll start off with the straightforward HTML:

<div id="wrapper">
	<div id="header">Header</div>
	<div id="content">
		<div id="content-left"></div>
		<div id="content-main"></div>
		<div id="content-right"></div>
	</div>
	<div id="footer"></div>
	<div id="bottom"></div>
</div>

These set of divisions give us the fundamental page structure to work from. The divisions have all been given IDs which enable the CSS to refer to each division and style them appropriately. It is worth noting that element IDs must always be unique within a page.

Now let's have a look at the CSS:


	body {
		font-family:arial,helvetica,sans-serif;
		font-size:12px;
	}

These first couple of lines in the style sheet specify the font family and size for the document.

	#wrapper {
		width:900px;
		margin:0px auto;
		border:1px solid #bbb;
		padding:10px;
	}

Here, the page width has been specified as 900 pixels. This wrapper division also has padding of 10 pixels and a border of 1 pixel. The total of these values results in the actual width of the page being 922 pixels.

	#header {
		border:1px solid #bbb;
		height:80px;
		padding:10px;
	}
	#content {
		margin-top:10px;
		padding-bottom:10px;
	}
	#content div {
		padding:10px;
		border:1px solid #bbb;
		float:left;
	}
	#content-left {
		width:180px;
	}
	#content-main {
		margin-left:10px;
		width:500px;
	}
	#content-right {
		margin-left:10px;
		width:134px;
	}
	#footer {
		float:left;
		margin-top:10px;
		margin-bottom:10px;
		padding:10px;
		border:1px solid #bbb;
		width:878px;
	}
	#bottom {
		clear:both;
		text-align:right;
	}

Go to page: 1  2  Next  

Tools:
Add htmlgoodies.com to your favorites
Add htmlgoodies.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

IT Management Networking & Communications Web Development Hardware & Systems Software Development Earthwebnews.com



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES