2
  1. I have one container div, which contains 3 divs inside it.
  2. When i write border:1px solid red for container div, border is shown only on top of these 3 child divs, but not around them.
  3. Below is css code.

    #cont { width:800px; margin-right:auto; margin-left:auto; border:1px dashed red; padding:2px; } #third, #second, #first { width:260px; float:left; margin:2px; } 

Html code:

![<div id="cont"> <div id="third"><p>A demo text </p></br> <p>A demo text </p></br> <p>A demo text </p></br> <p>A demo text </p></br> </div> <div id="second"><p>A demo text </p></br> <p>A demo text </p></br> <p>A demo text </p></br> <p>A demo text </p></br> </div> <div id="third"><p>A demo text </p></br> <p>A demo text </p></br> <p>A demo text </p></br> <p>A demo text </p></br> </div> </div>][1] 
2
  • 1
    add below the third div: <div style="clear: both;"></div> that most likely will do the trick Commented Jan 21, 2013 at 8:05
  • tried clear: right / left /both . . but no success. . Commented Jan 21, 2013 at 8:08

3 Answers 3

4

add overflow:hidden;

#cont {width:800px;margin-right:auto;margin-left:auto; border:1px dashed red;padding:2px; overflow:hidden;} 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks! it worked, could you explain a bit...because what i know about overflow doesn't explains me how this happens. (overflow: controls data which may overflow, from an element) so what caused overflow here?
This is rule, because child elements used floating, so must to remove floating. In this equivalent to clearfix. .clearfix{*zoom:1}.clearfix:after{content:".";height:0;visibility:hidden;display:block;clear:both} <div id="cont" class="clearfix">
0

<div style="clear:both;float:none;"></div> well solve your problem. added it under the div's

2 Comments

um . .yes it did. . .thanks for info. . but i need to float my child div to left. (oops my requirement ; 3 column layout)
you need to place the code that I gave you, before the last div in your code.
0

add overflow:hidden to the #cont element

1 Comment

how come i could not see, your answer first, as you replied before @jrkey . . . they say IE6 sucks, they say right. (i could see your post rendered properly in firefox) thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.