On 2007-03-11, Francesco Moi <francescomoi@usa.comwrote:
Quote:
Hi.
>
I'm trying to place three "<div class=foo>" boxes in the same line:
>
----html--------------------
><HTML><HEAD>
><link href="test.css" rel="stylesheet" type="text/css" />
></HEAD>
><body>
><div>
><div class="foo">1</div>
><div class="foo">2</div>
><div class="foo">3</div>
></div>
></body>
></HTML>
-------------------------
>
-------test.css----------
.foo
{
font-family: sans-serif;
font-size: 290%;
background-color: red;
margin: 5px;
width: 100px;
}
-----------------------
>
However, these three boxes are placed each in one line. What am I
doing wrong?
It's because div is display: block by default, and blocks start new
"lines", or at least, go beneath one another.
Add display: inline-block to .foo, or if you need it to work in FF or
IE, add float: left instead.
For completeness, display: inline is no good because you want to set the
widths on these boxes.