Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Equal Height Columns?

Tags:

html

css

In CSS, I can do something like this:

enter image description here

But I've no idea how to change that to something like:

enter image description here


Is this possible with CSS?

If yes, how can I do it without explicitly specifying the height (let the content grow)?

like image 834
Alix Axel Avatar asked Jan 22 '10 03:01

Alix Axel


People also ask

How do I make columns the same height in CSS?

If you need exactly 3 columns, use grid-template-columns: repeat(3, 1fr); instead. You can still have more elements, they will wrap, be responsive, but always be placed in 3 column layout. More on CSS Grid on MDN or css-tricks.

How do I make all boxes the same size in CSS?

With the CSS box-sizing Property The box-sizing property allows us to include the padding and border in an element's total width and height. If you set box-sizing: border-box; on an element, padding and border are included in the width and height: Both divs are the same size now!

How do you make two divs the same height side by side?

Basically what you do is make both divs/columns very tall by adding a padding-bottom: 100% and then "trick the browser" into thinking they aren't that tall using margin-bottom: -100% . It is better explained by Ed Eliot on his blog, which also includes many examples.


1 Answers

Grid

Nowadays, I prefer grid because it allows keeping all layout declarations on parent and gives you equal width columns by default:

.row {    display: grid;    grid-auto-flow: column;    gap: 5%;  }    .col {    border: solid;  }
<div class="row">    <div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>    <div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</div>    <div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.</div>  </div>

Flexbox

Use Flexbox if you want children to control column width:

.row {    display: flex;    justify-content: space-between;  }    .col {    flex-basis: 30%;    box-sizing: border-box;    border: solid;  }
<div class="row">    <div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>    <div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</div>    <div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.</div>  </div>
like image 194
Pavlo Avatar answered Sep 19 '22 16:09

Pavlo