I have float red divs on blue div like on picture
<div class="blue">
<div style="height: 40px; float: left"></div>
<div style="height: 40px; float: left"></div>
<div style="height: 40px; float: left"></div>
<div style="height: 40px; float: left"></div>
<div style="height: 40px; float: left"></div>
<div style="height: 40px; float: left"></div>
</div>
I want to do, so blue div have height on red DIVs. When I remove float it's OK.
Answer: Use the CSS3 flexbox With CSS3 flex layout model you can very easily create the equal height columns or <div> elements that are aligned side by side. Just apply the display property with the value flex on the container element and the flex property with the value 1 on child elements.
Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.
This seems like the ideal candidate for transition from a table-based layout to a CSS layout. It makes sense: both DIVs and tables can be nested, have HEIGHT and WIDTH attributes set, contain borders, etc.
You need to add display:table-cell; or overflow:hidden; to your blue div. This will give the parent the height of it's children.
Demo
like this:
.blue{
overflow:hidden;
//or
//display:table-cell;
}
a sidenote - your divs need a width when they are floating.
You also have the option to make your div with class blue float. But this might cause some unwanted behavior in your document (if the div is not supposed to float).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With