I’m trying to create a grid in bootstrap, when I add multiple columns (which will span multiple lines) into a single row it looks like this:
Here’s my code:
<div class="row">
<div class="col-md-4">
<div class="col-md-4"><img src="http://icons.iconarchive.com/icons/thiago-silva/palm/256/Photos-icon.png"></div>
<div class="col-md-8"><h4>Subheading</h4>Text goes here. <br /><br /> This one's a little longer and breaks the horizontal alignment with other columns.<br /></div>
</div>
<div class="col-md-4">
<div class="col-md-4"><img src="http://icons.iconarchive.com/icons/thiago-silva/palm/256/Photos-icon.png"></div>
<div class="col-md-8"><h4>Subheading</h4>Text goes here.</div>
</div>
<div class="col-md-4">
<div class="col-md-4"><img src="http://icons.iconarchive.com/icons/thiago-silva/palm/256/Photos-icon.png"></div>
<div class="col-md-8"><h4>Subheading</h4>Text goes here.</div>
</div>
<div class="col-md-4">
<div class="col-md-4"><img src="http://icons.iconarchive.com/icons/thiago-silva/palm/256/Photos-icon.png"></div>
<div class="col-md-8"><h4>Subheading</h4>Text goes here.</div>
</div>
<div class="col-md-4">
<div class="col-md-4"><img src="http://icons.iconarchive.com/icons/thiago-silva/palm/256/Photos-icon.png"></div>
<div class="col-md-8"><h4>Subheading</h4>Text goes here.</div>
</div>
<div class="col-md-4">
<div class="col-md-4"><img src="http://icons.iconarchive.com/icons/thiago-silva/palm/256/Photos-icon.png"></div>
<div class="col-md-8"><h4>Subheading</h4>Text goes here.</div>
</div>
</div>
If I use .row-eq-height
it converts it to a flexbox layout and indeed all of the rows are the same height, but it places every single column onto the same line like so:
Finally, my other option is to split each row into three different columns manually, which outputs the row how I’d like it do, but is also very impractical since the divs are added dynamically – some pages may only have 2 divs, some may have 10 or more.
Any ideas on how I can add a simple grid please, where each div/.col has the same height? Thank you.
3
Answers
Rather than using bootstrap for this, why not use custom classes?
that way, all you need to do is add a
vertical-align
to your elements.DEMO:
Some times it isn’t possible to use rows as @WhiteLine suggested because you may wish to use multiple
col-XX-XX
classes on the same element.The way I have solved this before is to add an empty
div
with theclearfix
class and avisible-XX
class to simulate row breaks.Bootply Demo
If you use multiple
col-XX-XX
classes you can use mutipleclearfix
divs that are visible at different resolutions…Example using multiple
col-XX-XX
classesHow about a flex solution? If you don’t need ancient browser support, this is the way to go.
It is possible to use the same method inside the containers, demo here:
http://jsfiddle.net/fpfbcs3c/