Recently found a good way: Since I experimented with elements in the style of float, so they behave correctly in a sensitive environment, it is not easy, rather like hell. If you want each element of the same βrowβ to have the same height, the best aproach for IE9 and above is flexbox.
Sample, we have 4 boxes that do not fit in the container, so we want them to move to a new line if they do not fit, but keep all the same heights (being unknown in height):
<div class="container"> <div class="element"> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et </p> </div> <div class="element"> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. </p> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et </p> </div> <div class="element"> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et </p> <p> Lorem ipsum dolor sit amet. </p> </div> <div class="element"> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et </p> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et </p> </div> </div>
Using these styles only fixes this:
.container { display: flex; display: -mx-flexbox; display: -webkit-flex; flex-grow: 0; -ms-flex-grow: 0; -webkit-flex-grow: 0; flex-wrap: wrap; width: 400px; background-color: red; } .element { flex: none; width: 120px; border: 1px solid blue; }
Check out this fiddle, it will give everything you want. https://jsfiddle.net/upamget0/
Source: CSS height 100% in automatic brother does not work in Chrome
More information can be found here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Leo armentano
source share