I have the following html code:
<div class="container">
<div class="row row1">
<div class="col col1 col-md-3">
Column 1
</div>
<div class="col col2 col-md-3">
Column 2
</div>
<div class="col col3 col-md-3">
<div class="row">
Column 3
</div>
<div class="row">
Column 4
</div>
</div>
</div>
I'm using bootstrap grid layout system and I want to achieve something like this:
The idea is that col1 and col2 should have the same height as col3 and col4 combined.
Is there a way of doing this without specifying the height of the container and setting height 100% on children elements as I did on this example?
Jsfiddle demo
The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which behaves like table.
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.
A complete solution for Bootstrap Equal Height columns with the help of flexbox with only 1 class. This works in all major browsers IE10+. Without this polyfill the columns will behave as usual Bootstrap columns so which is a quite good fallback.
Reading: How can I make Bootstrap columns all the same height?
You can use:
.row{
overflow: hidden;
}
[class*="col-"]{
margin-bottom: -99999px;
padding-bottom: 99999px;
}
Here's a runnable example:
.row{
overflow: hidden;
}
[class*="col-"]{
margin-bottom: -99999px;
padding-bottom: 99999px;
}
.row1 {
height: 100%;
}
.col1{
background-color: red;
color: white;
height: 100%;
}
.col2{
background-color: green;
color: white;
height: 100%;
}
.col3{
background-color: yellow;
height: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row row1">
<div class="col col1 col-xs-3">
Column 1
</div>
<div class="col col2 col-xs-3">
Column 2
</div>
<div class="col col3 col-xs-3">
<div class="row">
Column 3
</div>
<div class="row">
Column 4
</div>
</div>
</div>
</div>
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