Computer >> Computer tutorials >  >> Programming >> CSS

Create a Column Layout using CSS


To create a column layout,

Set the margin and padding of the complete document as follows 

<style>
   <!--
      body {
         margin:9px 9px 0 9px;
         padding:0;
         background:#FFF;
      }
    -->
</style>

Define a column with yellow color and later, we will attach this rule to a <div> −

<style>
  <!--
     #level0 {
         background:#FC0;
     }
   -->
</style>

Let us now define another division inside level0 −

<style>
   <!--
      #level1 {
         margin-left:143px;
         padding-left:9px;
         background:#FFF;
      }
   -->
</style>

Nest one more division and the complete code will be like −

<style>
 
   body {
      margin:9px 9px 0 9px;
      padding:0;
      background:#FFF;
   }

   #level0 {background:#FC0;}
   #level1 {
      margin-left:143px;
      padding-left:9px;
      background:#FFF;
   }

   #level2 {background:#FFF3AC;}
   #level3 {
      margin-right:143px;
      padding-right:9px;
      background:#FFF;
   }

   #main {background:#CCC;}
</style>
 
<body>
 
   <div id="level0">
      <div id="level1">
         <div id="level2">
            <div id="level3">
               <div id="main">
                   Final Content goes here...
               </div>
            </div>
         </div>
      </div>
   </div>

</body>