Chaps, I have run into some strange behaviour never seen it before, and it is really giving me a huge headache. I wonder if anybody can help me to understand why this is happening. Here is the link: http://antobbo.webspace.virginmedia.com/various_tests/floatProblem/test.htm
Look at the squares labelled 1,2,3,4 inside the red div. They are all floated left. Now, when I increase the height of div 2 (you could do that in firebug) you will notice that, as you expect, div 4 will be pushed down. But also div 3 is pushed down!? And I have been wracking my brain for hours today trying to understand why that happens. Needless to say I don't want it to happen, I only want the container just below the one whose height I have increased to be pushed down. Is it something stupid I am doing or have I run into some kind of floating bug?
There are a couple of things I should mentioned. I have tried to achieve the same result with positioning (absolute etc) but the problem is that divs 1 and 2 will contain text and therefore need to grow and shrinks and obviously with absolute positionoing you have to specify a height etc etc, so I would like to stick to
floating divs if it is ok.
So let's look at the relevant code:
<h2>Floating problem</h2>
<div class="mainWrapper">
<div class="one"><p>1</p></div>
<div class="two"><p>2</p></div>
<div class="three">
<p>3</p>
</div>
<div class="four">
<p>4</p>
</div>
</div>
.mainWrapper{
background-color:red;
width:630px;
height:400px;
}
.one{
width:310px;
height:120px;
background-color:magenta;
float:left;
margin-bottom:10px;
}
.two{
width:310px;
height:120px;
background-color:magenta;
float:left;
}
.three, .four{
width:310px;
height:150px;
background-color:yellow;
float:left;
}
.three{
margin-right:10px;
}
/* .subThree1{
width:150px;
height:150px;
background-color:black;
} */
.one{
margin-right:10px;
}
Any help will be much appreciated!
thanks