Connecting Tech Pros Worldwide Forums | Help | Site Map

CSS DIV: if block=inline and float=left, container collapses

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#1: Jun 30 '08
The frustrating thing with coding with divs instead of tables is trying to get them to "act" like they're inside each other.

I have a container div, and three sub-divs.

First contains a plus sign
Second contains a Title
Third contains a price

Expand|Select|Wrap|Line Numbers
  1.  
  2. <div class="adCont">
  3.             <div id="expandAd1" class="adSign">+</div>
  4.             <div class="adTitle">Title</div> 
  5.             <div class="adPrice" >$9<span class="cent">.95 /mo</span></div>
  6.         </div>
  7.  
  8.  
When I declare the three inner divs to float:left (I want them next to each other) , the display of course automatically treated as inline, even if you explicitly declare it as block.

I've played the clear attribute and couldn't get it to work.

What happens in FF (my standard) is that the container just collapses if there's no "real" hard content in it such as plain text, images, or a div that doesn't have the float attribute.

I'm no CSS expert, but I find my way except when it comes to problems like this.

Any help is appreciate it. Trying to finish this tonight,


Dan

PS: Span tag instead of div? I'll try that. but I think span acts just like a div with display inline.

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Jun 30 '08

re: CSS DIV: if block=inline and float=left, container collapses


UPDATE:

I set the container's float and it fixed it in firefox.

it was previously display:block and clear:both, but since my content does not mess up if this is float, i'm fine with it.
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,579
#3: Jun 30 '08

re: CSS DIV: if block=inline and float=left, container collapses


Quote:

Originally Posted by dlite922

The frustrating thing with coding with divs instead of tables is trying to get them to "act" like they're inside each other.

Divs don't act like tables because they are not tables. A table is a fixed grid element. To get divs to act like that, set their sizes, such as width:100%.
Quote:
the display of course automatically treated as inline, even if you explicitly declare it as block.
Divs are always block elements and don't need to be declared as such. Floated elements are NOT treated as 'inline' (just to not confuse others) but CAN line up in a row.

Quote:
What happens in FF (my standard) is that the container just collapses if there's no "real" hard content in it
This is correct behavior.

<span> works on inline elements, such as text or images in a <p>.
Reply