tags:

views:

54

answers:

5

hey guys,

I'm building a site and I have a proble.

I have a composed divs :

<div id="content">
<div id="left">
 <div id="leftcontent">...</div>
</div>
<div id="center">
 <div id="centercontent">...</div>
</div>
<div id="right">
 <div id="rightcontent">...</div>
</div>

How can I put left, center, and right in the same line ?

which code should I add ?

thanks!

+1  A: 

You can use float css attribute like:

#left   { float: left }
#center { float: left }
#right  { float: right }
Ivan Nevostruev
I would add that unless you want other things to also float, you need to do a "clear:both;" in the next element after the last div.
Russell Steen
You should also ensure the width is fit so that the three add up to 100% otherwise the center one could look wrong.
James Black
+1  A: 

Why are you using divs? A div has display of block, but a span would work better, as it is inline, then the float attribute suggested by Ivan would work well.

James Black
+1  A: 

This CSS should do the trick:

#left {
  width: 20%;
  float: left;
}

#center {
  width: 60%;
  float: left;
}

#right {
  width: 20%;
  float: left;
}

Adjust widths as appropriate.

Siddhartha Reddy
A: 

An alternative method is to use a css grid framework. Here are some of the popular ones:

  1. http://960.gs/
  2. http://www.blueprintcss.org/
  3. http://developer.yahoo.com/yui/grids/

My favorite happens to be: Object Oriented CSS

Using a css based grid system is somewhat recommended as they are very well tested to work across multiple browsers.

One possible negative effect, is that you have to structure your markup in a way that is specific to the framework you choose.

Jordan S. Jones
A: 

The other comments answer your question, but watch out that you're not starting the descent into div hell...divs doing nothing more than contain divs can be a code smell.

FinnNk
Actually, we call that 'divitis'.
Rob