I'm trying to build a pricing table where each column contains a card. I want all cards to stretch to the height of their parent (.col) elements.
Note: I'm using Bootstrap 4, and trying to achieve this with the existing grid system (for the sake of consistency) and with this particular piece of markup. I can't get the cards to grow to the height of their parent containers. Is this even possible with the current markup?
The basic markup is this:
<div class="row">
<div class="col">
<div class="card">
blah
blah
blah
</div>
<div class="card">
blah
</div>
<div class="card">
blah
</div>
</div>
</div>
Here is my pen: https://codepen.io/anon/pen/oZXWJB
You can make them equal by setting the div blocks' width to be 33.33% (you can also do math here like 100/3%, then press enter). Alternatively, you you can set the div blocks' flex child settings to Expand.
You can use Jquery's Equal Heights Plugin to accomplish, this plugins makes all the div of exact same height as other.
By default, a flex container has the following width and height assigned. width: auto; height: auto; But you can set a fixed height and width to the flex container.
The flex columns can be aligned left or right by using the align-content property in the flex container class. The align-content property changes the behavior of the flex-wrap property. It aligns flex lines. It is used to specify the alignment between the lines inside a flexible container.
Add flex-grow : 1;
to your .card
rule. HTML markup is fine.
.row {
display: flex;
flex-flow: row wrap;
background: #00e1ff;
margin: -8px;
}
.col {
display: flex;
flex: 1 0 400px;
flex-flow: column;
margin: 10px;
background: grey;
}
.card {
display: flex;
padding: 20px;
background: #002732;
color: white;
opacity: 0.5;
align-items: stretch;
flex-direction: column;
flex-grow: 1;
}
You may also look at Foundation 6 Equalizer plugin. They use JavaScript though.
You just need to add height: 100%
on .card
.card {
display: flex;
padding: 20px;
background: #002732;
color: white;
opacity: 0.5;
align-items: stretch;
flex-direction: column;
height: 100%;
}
DEMO
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