Home arrow Style Sheets arrow Page 3 - Creating DIV-based CSS Tables
STYLE SHEETS

Creating DIV-based CSS Tables


In the last few years, divs have became very popular with many web designers, particularly when it comes to building the layout of the many different pages that comprise a web site. And certainly, this table-less approach has proven to be quite successful over time. It permits developers to create both liquid and fixed designs with relative ease by using a standard methodology. Unfortunately, one aspect of the approach can cause web pages to display in very different ways on different browsers. This four-part series will show you an important workaround.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 12
December 30, 2008
TABLE OF CONTENTS:
  1. · Creating DIV-based CSS Tables
  2. · A three-column web page layout using a floating-div approach
  3. · Using CSS tables to create a two-column web document layout
  4. · Structural markup for a two-column web document layout

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Creating DIV-based CSS Tables - Using CSS tables to create a two-column web document layout
(Page 3 of 4 )

Put in a simple way, building web page layouts by using CSS tables is a procedure that relies on specifying that the divs that comprise the pertinent web document must behave as typical table elements. It’s that simple.

The crucial question that comes up here is: how can this be achieved with plain CSS code? Well, it’s possible to use the “display” property that you’ve probably utilized hundreds of times before to indicate to the browser that some selected divs must be laid out as table components.

In this case, since I’m planning to construct a layout comprised of a main column along with a side bar, the set of CSS styles that would render this design would be the following:

#maincol, #sidebar{

display: table-cell;

}

#tablewrapper{

border-collapse: collapse;

display: table;

table-layout: fixed;

}

#sidebar{

width: 20%;

padding: 10px;

background: #eee;

}

#maincol{

width: 80%;

padding: 10px;

}


As shown above, here’s where the magic of CSS tables really happens! As you can see, I defined two selectors identified as “sidebar” and “maincol” respectively, which obviously are the principal containers of this two-column layout. However, you should pay attention to the code that instructs these divs to behave as table cells. The following CSS declaration:


#maincol, #sidebar{

display: table-cell;

}


tells the browser that the corresponding divs should be rendered as table cells, instead of being shown as regular containers. Besides, it’s very important to note that I created an additional “tablewrapper” div, which will be displayed as a regular HTML table, since it’s been assigned the following CSS styles:


#tablewrapper{

border-collapse: collapse;

display: table;

table-layout: fixed;

}


It’s hard to believe, but that’s all the CSS code required to create a simple two-column web page layout by using CSS tables. Of course, this approach doesn’t demand the use floating divs, and indeed the CSS styles are much easier to read and code. Unfortunately, Internet Explorer doesn’t completely support this technique, but as I mentioned in the introduction, it seems that the engine included into its eighth version will be completely compliant with it.

So far, so good. At this point, you've hopefully learned the basics of using CSS tables to construct a two-column web page layout. However, this introductory example looks rather disjointed in its current incarnation, since it requires us to tie the previous CSS styles to the corresponding structural markup.

Thus, in the section to come I’m going to put all of these elements into one single file, so you can see more clearly how they link with each other.

Now, jump ahead and read the new few lines. We’re almost finished!


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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