Reputation: 85545
I wanted to achieve like this
+-----------+----------------+----------------+
| | | |
+-----------+----------------+----------------+
but got like this
+-----------+----------------+
| | |
+-----------+----------------+----------------+
| |
+----------------+
Here is DEMO
Upvotes: 1
Views: 127
Reputation: 2845
Here is a possible solution:
http://jsfiddle.net/bFqTv/28/
.wrap{width: 500px; background: red; position: relative; margin: 0 auto;}
.one{width: 200px; float: left; background: blue;}
.three{width: 200px; float: left; background: blue;}
.two{ width:100px; float:left;}
/**Source:http://nicolasgallagher.com/micro-clearfix-hack/**/
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}
Upvotes: 0
Reputation: 2840
You just need to do two things:
float: left;
width: 33%
Updated CSS:
.wrap{
width: 500px;
margin: 0 auto;
}
.one, .two, .three {
float: left;
width: 33%;
}
.one, .three {
background-color: blue;
}
.two{
background-color: red;
}
You HTML:
<div class="wrap cf">
<div class="one">one</div>
<div class="two">two</div>
<div class="three">three</div>
</div>
Here's a working example: http://jsfiddle.net/bFqTv/29/
Upvotes: 0
Reputation: 193261
Your code is fine, but you need to change the order of the elements:
<div class="wrap cf">
<div class="one">one</div>
<div class="three">three</div>
<div class="two">two</div> <!-- put the element without class right to the end -->
</div>
Upvotes: 3
Reputation: 3263
.wrap{width: 500px; background: red; position: relative; margin: 0 auto}
.one{width: 100px; float: left; background: blue;}
.three{width: 100px; float: left; background: blue;}
.two{width:100px; float: left;}
If require background red for second div use below
.wrap{width: 500px; background: red; position: relative; margin: 0 auto}
.one{width: 100px; float: left; background: blue;}
.three{width: 100px; float: left; background: blue;}
.two{width:100px; float: left; background: red;}
Thanks
Upvotes: 0
Reputation: 5636
In you first class name in HTML is wrap cf but you are using only wrap in your CSS.I think you need to set your 3 div inside 500px width.Use CSS like i mentioned
.wrap cf{width: 500px; background: red; position: relative; margin: 0 auto;}
.one{width: 200px; background: blue;float: left}
.three{width: 100px; background: green; float: left}
.two{width: 200px; background: red; float: left }
This CSS works well on my side.Hope it works on your side as well.
Upvotes: 0
Reputation:
Use following CSS if you don't want to increase the width:
.wrap cf{width: 500px; background: red; position: relative;}
.one{width: 200px; float: left; background: blue;}
.three{width: 200px; background: blue;float:left;}
.two{width:200px;float:left;background:red;}
Upvotes: 4
Reputation: 518
This is one way to do it:
.wrap{width: 500px;overflow:hidden; background: red; position: relative; margin: 0 auto;}
.one{width: 200px; float: left; background: blue;}
.three{width: 200px; float: left; background: blue;}
.two{width: 100px; float: left;}
NB clear the float properly rather than just overflow: hidden
Upvotes: 0
Reputation: 5582
If all you need to do is keep those DIVs (one, two and three) in a row, they all need to fit within 500px like this:
.wrap{width: 500px; background: red; position: relative; margin: 0 auto;}
.one{width: 200px; float: left; background: blue;}
.three{width: 100px; float: left; background: blue;}
.two{width: 200px; float: left; background: red;}
Also note that I've given width for every DIV
Upvotes: 0
Reputation: 3546
You have a wrapper of 500px, and try to fit three (3) boxes in it of 200px? That just can't work... Enlarge your wrapper until it fits the sum of all the boxes you want to have in it. Or make your boxes smaller...
Oh, and make sure you enlarge your window enough to show the full xxx pixels...
Upvotes: 0
Reputation: 8881
you need to increase the width
in .wrap
, I increased it to 800
and all are in one line
Upvotes: 0