Style Sheets
  Home arrow Style Sheets arrow Page 6 - DIV Based Layout with CSS
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

DIV Based Layout with CSS
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 405
    2004-12-21

    Table of Contents:
  • DIV Based Layout with CSS
  • The table-based approach
  • The mighty DIV tag
  • Fixed layout design with fixed boxes
  • Three-column fixed layout
  • Fixed layout design with floating boxes
  • Adding a right column
  • Liquid design with floating boxes
  • Three-column liquid layout with floating boxes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    DIV Based Layout with CSS - Fixed layout design with floating boxes


    (Page 6 of 9 )

    Since we have developed a couple of examples giving absolute positions to each DIV, the next step is building the same schema, this time using the “float” property. Originally, the float property was not intended for building Web page layouts. It’s commonly used to make text float around images or similar page structures. Possible values for float are: left (element floats to left), right (element floats to the right), none (element doesn’t float), and inherit (element inherits from its parent). However, we can apply this property to our DIVS, and get the same effect as with fixed boxes. Let’s see how it works:

    <style type="text/css">
    <!--
    body {
      margin: 0px;
      padding: 0px;
    }
    #header {
      background: #0f0;
      width: 800px;
      height: 100px;
    }
    #leftcol {
      background: #f00;
      float: left;
      width: 150px;
      height: 500px;
    }
    #content {
      background: #fff;
      float: left;
      width: 650px;
      height: 500px;
    }
    #footer {
      background: #0f0;
      clear: both;
      width: 800px;
      height: 100px;
    }
    -->
    </style>

    The corresponding HTML is like this:

    <div id="header">Header Section</div>
    <div id="leftcol">Left Section</div>
    <div id="content">Content Section</div>
    <div id="footer">Footer Section</div>

    Again, we present the complete code:

    <html>
    <head>
    <title>TWO-COLUMN FIXED LAYOUT WITH FLOATING BOXES</title>
    <style type="text/css">
    <!--
    body {
      margin: 0px;
      padding: 0px;
    }
    #header {
      background: #0f0;
      width: 800px;
      height: 100px;
    }
    #leftcol {
      background: #f00;
      float: left;
      width: 150px;
      height: 500px;
    }
    #content {
      background: #fff;
      float: left;
      width: 650px;
      height: 500px;
    }
    #footer {
      background: #0f0;
      clear: left;
      width: 800px;
      height: 100px;
    }
    -->
    </style>
    </head>
    <body>
    <div id="header">Header Section</div>
    <div id="leftcol">Left Section</div>
    <div id="content">Content Section</div>
    <div id="footer">Footer Section</div>
    </body>
    </html>

    There is something really interesting going on. We have applied the float property to the “leftcol” DIV, making it float to the left. Then, we made the content DIV float to the left too, sticking the two boxes to each other. The same layout effect has been achieved, making the boxes float. Please note, all absolute position declarations were removed, as well as top and left coordinates properties, so the whole file size has been decreased.

    Finally, as to making our footer display correctly, we have “cleared” the float properties previously declared. Pretty good, isn’t it? The visual output is almost identical to that achieved with fixed boxes.

    DIV Based Layout with CSS

    More Style Sheets Articles
    More By Alejandro Gervasio


       ·  Concerning to webpage layout, althougt tables are the most used elements, a CSS...
       · Its definately more accessible.Keep tables for tabular data, not...
       · I've read the article and esp. the last page ("Three-column liquid layout with...
       · Jacob - you could give the left and right menu div's (not cells!) fixed widths, then...
       · The nice thing about designing with tables is that the heights of all columns in a...
       · Another nice thing about designing with tables is the fact that people with...
       · In regards to the "Three-Column Liquid Layout With Floating Boxes", is it possible...
       · Hi,Regarding your question, yeap, it's possible set fixed sizes to left and...
       · Check this article out on alistapart...
       · Just define #leftcol and #rightcol in pixel width and #content width:auto - like...
       · its bad to use position/presentation words in your IDs and class names... words such...
       · Hi there,I agree with your naming concepts. It's only for example...
       · Nice attack!
       · This seems to be a trend with your articles - "only for example sake". You should...
       · Dear Sr.Your comments and suggestions are very welcome. In fact, every time I...
       · I'm not sure what youre reply means, but if anything, seperation of application...
       · I get your point of view, and it's right.I liked your naming examples, showed...
       · tried your fixed width left and right cols and it breaks in Safari. when content...
       · Regarding the solution proposed by the previous poster, that won't work on Safari,...
       · I agree with the above concept too.
       · How do I center the page as a whole when using div tags?
       · Hello,There are numerous methods to center a page so you may want to select a...
       · I pretty much followed the instructions, haven't put css in separate sheetyet but...
       · Just a little word about fixed size.Using pixel size (px) for dimension is as...
       · Thank you for commenting on my DIV-based layout article. Also, I found your opinions...
       · How do you put your CSS in a separate page and still have it work with the current...
       · Thank you for the comments on my CSS article. Regarding your question, first save...
       · Short of having a fixed width container, I wonder if its possible to use the float...
       · Thank you for commenting on my article. With reference to your question, yes,...
       · Relax, Yodah. Not everyone is designing a site for the blind.
       · Thank you for posting your the comments on my DIV-layout article. They're greatly...
       · Not only is that incorrect, but it was god-awful rude.In truth, tabled design IS...
       · this is international level class and id name
       · Thank you for the comments on my article. They're greatly...
       · Very nice article. I learn new thing today.But sometimes we need merged cells and...
       · Thank you for commenting on my article, and it’s good to know it’s been useful to...
       · I have not agree your commd
       · Thank you for posting your comments on my CSS article. And I’m glad to see it...
       · really great article! It helped me a lot to understand the concepts of div...
       · Thank you for the kind comments on my CSS article. Also, it’s good to know it’s been...
       · A table does not leave you with a fixed layout. Why not use tables and make them...
       · Thanks for posting your comments on my CSS article. Yes, liquid tables are great and...
       · This article was helpful. Thanks very much. One feature that I would like to...
       · Thank you for the kind comments on my article. Concerning your question, you may...
       · Is this possible that the header is fluid - 100%, the right and left columns are 19%...
       · Thank you for the comments on my article. Concerning your question, yes, it's...
       · With http://www.quirksmode.org/css/centering.html received a 404 not found error...
       · Thank you for commenting on my CSS article. Since the above link was posted a few...
       · DIV based design is the correct thing to do while designing a web site that should...
       · Thank you for commenting on my article. Yes, divs are by far more accessible than...
       · Hi,i have to work with CLF2, and therefore have to replace pretty much all of my...
       · Thanks for the comments on my article. Concerning your question, I suggest you to...
       · Thank you for the article. It was very useful.Table layout is much more powerful...
       · Thanks for the kind comments on my article and your insightful post. In my personal...
       · DIV styling is superior to tables, I will now backup why this is, 1. Betting...
       · Thanks for the comments on my article. Of course, I agree on that divs are the...
       · in the body it says

    <div id="rightcol">Left Section</div>

    describing...
       · Thanks for pointing out that small bug. Anyway, it doesn't affect at all the way the...
       · Shouldn't footer start 600px from top?
       · It’s not an error. Actually, you can assign the value you want to an...
       · Nobody's mentioned one of the main reasons we avoid using tables for page structure....
       · While what you say on HTML tables is true, that’s not the reason why they should be...
       · Hey Guys,I majorly focus on Accessibility and Usability of the web pages and...
       · If you use standard markup and stick to the most common CSS properties, even IE 6...
       · thanks a lot, this is a good tut for the div n00b.
       · Glad to know my article has been useful to you.Regards.
       · I'm no web designer or developer...far from it but I had to make some mods on a...
       · Thanks for the comments, man. It’s good to know my article has been useful for you...
       · HiI am new to this stuff so please forgive me.I did a cut and paste of the...
       · No problem at all. It looks like you saved your file with a .txt extension instead...
       · Have just started using a DIV layout for my webpage at www.acres-wild.com instead of...
       · Hey Mansoor,If you want the pop-up menu to appear on a mouseover event, you can...
       · So if you still want such a layout, you're stuck with tables? I'm trying to design a...
       · No, you shouldn’t use tables for creating your web page layouts, unless you need to...
       · I love the article and the simplistic explainations and the very concise coding! I...
       · Thanks for the kind comments. With reference to your question, it looks like you...
       · Thanks for the tutorial, Ive been Putting off using div tags with css because i...
       · Thanks for the kind comments on my article. Glad to know you found it...
     

    STYLE SHEETS ARTICLES

    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...
    - Pulling Web Page Elements with the Blueprint...
    - Pushing Web Page Columns with the Blueprint ...
    - Controlling Column Padding with the Blueprin...
    - Prepending Classes in the Blueprint CSS Fram...
    - Appending Grid Units with the Blueprint CSS ...
    - Changing Grid Units in the Blueprint CSS Fra...
    - The Blueprint CSS Framework
    - Building a Liquid Design with Evened Margins...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT