![]() | Web Design / HTML |
Other CSS Positioning TipsAdvanced CSS ArticlesTableless LayoutsUsing CSS Positioning to Layout Web PagesThe first thing you should be aware is that this site is not built using these techniques. The Web Design site on About (and all About sites) is built using tables, and until browsers that support CSS Positioning are more widely used, will be for the foreseeable future. Browser SupportCSS Positioning (CSS-P) is the only way to create standards based Web pages using XHTML. Why? Because XHTML requires that tables only be used to define tabular data, and not be used for layout. The problem is, until recently, most browsers only had sketchy support of CSS-P. But now, the following browsers and versions, have minimal to good support of CSS-P, among others:
Rethinking How You Build a PageWhen you build a site using tables, you have to think in a "tabular" format. In other words, you're thinking in terms of cells and rows and columns. And your Web pages will reflect that. When you move to a CSS-P design, you'll start thinking of your pages in terms of the content. For example, the page for this article can be considered to have five content parts:
Rather than putting those elements in a table, I can use the <div></div> tag to define the different portions of the content, and then use CSS-P to place the content elements on the page. For the sake of this article, I'm going to pretend there are just three columns on the page, and ignore the header and footer. Identifying Your SectionsOnce you've defined the different content areas of your site, you need to write them in your HTML. While you can, generally, place your sections in any order, it's a good idea to place first items you'd like less advanced browsers to see first. For my three column layout, I'm going to have three sections:
These will be defined using div tags with the id attribute. Remember, when you use the id attribute, you need to have a unique name for each id.
PositioningThis is the fun part. Using CSS you can define the position for your id'ed divs.
Store your position information in a style call like this: Content within a div tag will take up as much space as it can, namely 100% of the width of the current location, or the page. So, to affect the location of a section without forcing it to a fixed width, you can change the padding or the margin elements. For this layout, I set the two navigation columns to fixed widths and then set their position absolute, so that they wouldn't be impacted by where they are found in the HTML. #leftnavigation { Then for the content row, I set the margins to be somewhat relative to the outer columns. While the page won't look wonderful in non-CSS-P browsers, as you can see, it is possible to define how your page will look without any table tags. See the HTML. See the CSS. Other CSS Positioning TipsAdvanced CSS Articles |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


