Connecting Tech Pros Worldwide Help | Site Map

Three "<div class=foo>" boxes in the same line, is it possible?

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 11th, 2007, 11:15 AM
Francesco Moi
Guest
 
Posts: n/a
Default Three "<div class=foo>" boxes in the same line, is it possible?

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?

Thank you very much.


  #2  
Old March 11th, 2007, 11:15 AM
Ben C
Guest
 
Posts: n/a
Default Re: Three "<div class=foo>" boxes in the same line, is it possible?

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.
  #3  
Old March 11th, 2007, 03:45 PM
Jukka K. Korpela
Guest
 
Posts: n/a
Default Re: Three "<div class=foo>" boxes in the same line, is it possible?

Scripsit Ben C:
Quote:
Quote:
>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.
Alternatively, set position: relative for the outer div and use "absolute"
positioning for the inner divs. "Absolute" positioning then means
positioning relative to the outer div.

In a simple case, float: left is probably simplest. Remember to use clear:
both for the element after the divs to stop floating.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

  #4  
Old March 11th, 2007, 07:25 PM
scripts.contact@gmail.com
Guest
 
Posts: n/a
Default Re: Three "<div class=foo>" boxes in the same line, is it possible?

On Mar 11, 9:31 am, "Jukka K. Korpela" <jkorp...@cs.tut.fiwrote:
Quote:
Quote:
Quote:
However, these three boxes are placed each in one line. What am I
doing wrong?
Quote:
Quote:
Add display: inline-block to .foo, or if you need it to work in FF or
IE, add float: left instead.
>
Alternatively, set position: relative for the outer div and use "absolute"
positioning for the inner divs. "Absolute" positioning then means
positioning relative to the outer div.

Alternatively, use nobr tag.

  #5  
Old March 11th, 2007, 08:05 PM
Ben C
Guest
 
Posts: n/a
Default Re: Three "<div class=foo>" boxes in the same line, is it possible?

On 2007-03-11, scripts.contact@gmail.com <scripts.contact@gmail.comwrote:
Quote:
On Mar 11, 9:31 am, "Jukka K. Korpela" <jkorp...@cs.tut.fiwrote:
Quote:
Quote:
>However, these three boxes are placed each in one line. What am I
>doing wrong?
>
Quote:
Quote:
Add display: inline-block to .foo, or if you need it to work in FF or
IE, add float: left instead.
>>
>Alternatively, set position: relative for the outer div and use "absolute"
>positioning for the inner divs. "Absolute" positioning then means
>positioning relative to the outer div.
>
Alternatively, use nobr tag.
The drawback with using position: absolute is that you will have to set
the "left" property on each block to position it on the line. With float
or inline-block, the browser works out those positions for you.

The problem with using the nobr tag is that, apart from being
nonstandard (the white-space property is preferred) it only affects how
inline boxes are broken to fit across lines. Since the OP wants to set
width on these boxes, they cannot be inline, and will therefore be
unaffected by nobr.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.