Forum Moderators: not2easy
<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! [edited by: DrDoc at 2:05 am (utc) on Jul 20, 2013]
[edit reason] Link. See forum charter [webmasterworld.com] [/edit]
A float is a box that is shifted to the left or right on the current line.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
.outer {
width:590px;
margin:auto;
overflow:hidden;
background:red;
}
.fl {
float:left;
width:280px;
margin:5px;
height:100px;
background:yellow;
}
.even {
float:right;
height:120px;
background:magenta;
}
</style>
</head>
<body>
<div class="outer">
<div class="fl ">1</div>
<div class="fl even">2</div>
<div class="fl">3</div>
<div class="fl even">4</div>
<div class="fl">5</div>
<div class="fl even">6</div>
<div class="fl">7</div>
<div class="fl even">8</div>
</div>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
.outer {
width:590px;
margin:auto;
overflow:hidden;
background:red;
}
.fl {
float:left;
width:280px;
margin:5px;
height:100px;
background:yellow;
}
.even {
float:right;
height:120px;
background:magenta;
}
.small { height:20px }
</style>
</head>
<body>
<div class="outer">
<div class="fl ">1</div>
<div class="fl even">2</div>
<div class="fl">3</div>
<div class="fl even small">4</div>
<div class="fl">5</div>
<div class="fl even">6</div>
<div class="fl">7</div>
<div class="fl even">8</div>
</div>
</body>
</html>
What _I_ can't figure out is why, if you remove the width constraint on the wrapper and widen the window, float 4 ends up under float 3 instead of under float 1-- and now there's no intervening vertical space.