Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would one create a 2-column grid of perfectly square images in bootstrap?

The columns are responsive, so the width changes on different screen sizes. The images are all different sizes and aspect ratios. I can't use the .thumbnail class inherent in bootstrap as it has a lot of styling options I don't want.

like image 738
flaskehals Avatar asked Dec 24 '14 22:12

flaskehals


People also ask

How do I add a grid in Bootstrap?

Basic Structure of a Bootstrap Grid So, to create the layout you want, create a container ( <div class="container"> ). Next, create a row ( <div class="row"> ). Then, add the desired number of columns (tags with appropriate .col-*-* classes). Note that numbers in .col-*-* should always add up to 12 for each row.

How many columns are used for grid system by Bootstrap?

Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a twelve column system, five default responsive tiers, Sass variables and mixins, and dozens of predefined classes.

What is Bootstrap grid column?

Bootstrap includes predefined classes for creating fast, responsive layouts. With six breakpoints and a dozen columns at each grid tier, we have dozens of classes already built for you to create your desired layouts. This can be disabled via Sass if you wish.


1 Answers

HTML

<div class="row">
    <div class="col-xs-6">
         <div class="square"></div>
    </div>

    <div class="col-xs-6">
        <div class="square"></div>
    </div>
</div>

CSS

.square {
    width: 100%;
    padding-bottom: 100%;
    background-image: url('your_img');
    background-size: cover;
}

This will try to fit as much of the image as possible into the squares. It will possibly omit some of an image if its got an aspect ratio a long way from 1:1, but is probably your best bet.

like image 118
timminss Avatar answered Oct 13 '22 21:10

timminss