Reputation: 22480
can someone please tell me what I am doing wrong here. I've tried to write the clear:both; also inside the floated elements but nothing seems to work.
I would like those small orange boxes inside the green border and not like this (see image).
Fiddle here and code:
<style type="text/css">
.wrap {
border:solid 2px green;
}
.wrap div {
margin: 0 0 0 10px;
padding: 10px;
text-align: center;
width: 67px;
float:left;
}
.wrap div span {
display:block;
background-color:orange;
margin:2px;
}
.clear {
clear:both;
}
</style>
<div class="wrap">
<div>
<span>xx</span>
<span>xx</span>
<span>xx</span>
</div>
<div>
<span>yy</span>
<span>yy</span>
<span>yy</span>
</div>
<div>
<span>zz</span>
<span>zz</span>
<span>zz</span>
</div>
<div class="clear"></div>
</div>
Upvotes: 1
Views: 408
Reputation: 2394
You're floating the <div class="clear">
. That's why it does not work.
Try this selector for the floating divs
instead so it does not match the clearing div
:
.wrap div:not(.clear) {
margin: 0 0 0 10px;
padding: 10px;
text-align: center;
width: 67px;
float:left;
}
Another way of solving this, is to add float: none
to your clearing class:
.clear {
clear: both;
float: none !important;
}
Upvotes: 2
Reputation: 946
Alternatively use
.wrap {
border: solid 2px green;
overflow: hidden;
}
and remove the <div class="clear"></div>
All of the other answers are perfectly fine too. Enjoy learning about floats!
Upvotes: 0
Reputation: 15699
It is happening because .wrap
does not have any height.
Add
overflow:hidden;
to .wrap
. It will give height to it.
Upvotes: 1
Reputation: 3657
.wrap {
border:solid 2px green;
overflow:hidden;
}
This should be in your css.
Upvotes: 0
Reputation: 17929
add
display: inline-block;
to your wrap
container css
Fiddle: http://jsfiddle.net/Pv6m2/1/
Upvotes: 4