Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple two column html layout without using tables

Tags:

html

css

I'm looking for a super easy method to create a two column format to display some data on a webpage. How can i achieve the same format as:

<table>     <tr>         <td>AAA</td>         <td>BBB</td>     </tr> </table> 

I'm open to HTML5 / CSS3 techniques as well.

like image 208
Fixer Avatar asked Jun 17 '11 11:06

Fixer


People also ask

How we split the page as two columns without using table in HTML?

Make sure that the sum of the colum-widths equals the wrap width. Alternatively you can use percentage values for the width as well. Actually, you don't really need to float anything to the right, both divs can have the float to the left and the effect is the same as what was request by the OP.

How do I put two columns together in HTML?

To merge table columns in HTML use the colspan attribute in <td> tag. With this, merge cells with each other. For example, if your table is having 4 rows and 4 columns, then with colspan attribute, you can easily merge 2 or even 3 of the table cells.

What can I use instead of a table in HTML?

The below table gives you the relation between a 'table' tag and the corresponding supported CSS property to represent the same element. So, when creating a table, all you need to do is, instead of the HTML 'table' tag, merely use the 'div' tag and add the corresponding CSS to display a table.

How do I create a two column template?

In Word 2007, click the Page Layout tab, choose Breaks in the Page Setup section, and click Continuous in the drop-down menu. In Word 2003, click Format > Columns and choose the two-column icon under Presets. In Word 2007, click the Page Layout tab on the ribbon and click Columns > Two.


2 Answers

<style type="text/css"> #wrap {    width:600px;    margin:0 auto; } #left_col {    float:left;    width:300px; } #right_col {    float:right;    width:300px; } </style>  <div id="wrap">     <div id="left_col">         ...     </div>     <div id="right_col">         ...     </div> </div> 

Make sure that the sum of the colum-widths equals the wrap width. Alternatively you can use percentage values for the width as well.

For more info on basic layout techniques using CSS have a look at this tutorial

like image 174
Dennis Traub Avatar answered Sep 22 '22 13:09

Dennis Traub


Well, you can do css tables instead of html tables. This keeps your html semantically correct, but allows you to use tables for layout purposes.

This seems to make more sense than using float hacks.

    #content-wrapper{       display:table;     }          #content{       display:table-row;     }          #content>div{       display:table-cell     }          /*adding some extras for demo purposes*/     #content-wrapper{       width:100%;       height:100%;       top:0px;       left:0px;       position:absolute;     }     #nav{       width:100px;       background:yellow;     }     #body{       background:blue;     }
<div id="content-wrapper">   <div id="content">     <div id="nav">       Left hand content     </div>     <div id="body">       Right hand content     </div>   </div> </div>
like image 27
RobKohr Avatar answered Sep 23 '22 13:09

RobKohr