Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 grid with different height in each item - is it solvable using only CSS?

I'm trying to make a grid of thumbnails, where each thumbnail has an image and a label. It works fine if all the labels have the same length, because then all the thumbnails have the same height:

http://www.bootply.com/iSqwWyx5ms

However, if I shorten the rightmost thumbnail's text, part of the row below gets pushed into a new row, as shown here:

http://www.bootply.com/Wqd021aaeM

What I would like is the second row to start from the lowest point in which the first row ended.

I know I can solve it with JavaScript - find the longest thumbnail in each row and set the other thumbnails to have that height. Question is, do I have any way of doing it, or something else that can solve my problem, using only with CSS?

Update: I don't know beforehand how many items I have in one row. For example, on a small screen I'd have 2 items in a row, while on a bigger screen it'll be 3, so solutions which set when a new row starts aren't good for me.

like image 367
haimlit Avatar asked Jul 05 '14 20:07

haimlit


People also ask

Can I use Bootstrap with CSS grid?

CSS grid and bootstrap grid can work together perfectly. Rather than pit them against each other, it's up to you to find a way to blend these two powerful grids.

Is Bootstrap better than CSS grid?

If you're layout-first, meaning you want to create the layout and then place items into it, then you'll be better off with CSS Grid. But if you're content-first, meaning you have items that you want to place into a container and space out evenly, go with Bootstrap.

How do I change the grid size in Bootstrap?

Go to the Customize menu on Bootstrap website and choose your preferred size. In Less Variables -> Grid system you can find a form to input your preferred sizes. Then you can easily download the preferred grid. Hope this will help.

What is offset 3 in Bootstrap?

offset-md-3 which will offset the desired column element with 3 columns to the right from its default position on medium screen sizes and above. . offset classes always shifts its content to the right. This all stuff produced results .


2 Answers

You should use .clearfix, as described at the Grid responsive resets section of the Bootstrap documentation: https://getbootstrap.com/docs/3.3/css/#grid-responsive-resets

like image 117
gbellmann Avatar answered Sep 24 '22 07:09

gbellmann


If you don't know how many columns you have, you can do:

.row.fix {   display: flex;   flex-wrap: wrap;   width:100%; /*not always necessary*/ } 

Working fiddle: https://jsfiddle.net/wqdm1jjt/

Example: enter image description here

Author: Juan Miguel

like image 24
Lucas Bustamante Avatar answered Sep 22 '22 07:09

Lucas Bustamante