Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I space these images inside of a Bootstrap 3 grid system?

I am wondering which is the best way to put spaces in between these 3 images with CSS using Bootstrap 3 RC2 as what I have done at the moment is not auto-resizing the images, even though I have set the width to auto in my #picture id tag. I wish for them to b inline and resize the images accordingly.

Here is my markup:

<div class="container">
    <div class="row">
        <div class="col-lg-4">
            <img src="http://placehold.it/350x250" id="picture" />
        </div>
        <div class="col-lg-4">
            <img src="http://placehold.it/350x250" id="picture" />
        </div>
        <div class="col-lg-4">
            <img src="http://placehold.it/350x250" id="picture" />
        </div>
    </div>
</div>

CSS:

.container {
    max-width:1000px;
    background-color:white;
}
body {
    background-color:cyan
}
#picture {
    width:auto;
    /*margin-left:10px; */
    /*margin-right:10px; */
}
.col-lg-4 {
    margin-left:10px;
    margin-right:10px;
}

Check my Fiddle for a clearer view. Is there a better way to go about handling this?

like image 862
ProEvilz Avatar asked Aug 18 '13 23:08

ProEvilz


People also ask

How do I arrange images in a row in Bootstrap?

You can use Bootstrap's alignment classes. Just add the . text-center class to the row.

How do I center an image in Bootstrap grid?

Answer: Use the center-block Classcenter-block on it, along with the . img-responsive class in Bootstrap 3. The .

How do I customize Bootstrap grid?

Just check the Grid System block on the Customize page. The @grid-columns field allows to set a different number of columns, and the @grid-gutter-width field lets you change the gutter width. Customizers are convenient when bootstrap. css is the only file you need and when you don't work with preprocessors.

What is the basic structure of a bootstrap grid?

Basic Structure of a Bootstrap Grid. The following is a 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).

What is the best way to organize content in Bootstrap?

Bootstrap's grid system is responsive, and the columns will re-arrange depending on the screen size: On a big screen it might look better with the content organized in three columns, but on a small screen it would be better if the content items were stacked on top of each other. Tip: Remember that grid columns should add up to twelve for a row.

How to create a bootstrap grid with 3 equal columns?

For example, three equal columns would use three .col-sm-4 Column widths are in percentage, so they are always fluid and sized relative to their parent element The following is a basic structure of a Bootstrap grid: ... So, to create the layout you want, create a container ( <div class="container"> ).

How to add an image grid to bootstrap card?

Images can be added to the Bootstrap card by simply using an img tag. But we cannot use the same method directly to place an Image Grid into the Bootstrap Card as it will be lead to a misaligned design.


2 Answers

Remove your own CSS for .col-lg-4: these margins may screw up the Bootstrap CSS. Next to that, these columns are only visible when your screen width is bigger than 1200 px.

Add the following classes to your divs: .col-xs-4 .col-sm-4 and .col-md-4, and give images a class="img-responsive" attribute.

It should work now as you wish.

like image 117
Harm Wellink Avatar answered Oct 31 '22 21:10

Harm Wellink


As Harm Wellink mentioned, remove your css. You should only need the following html. Notice the "col-xs-4" and the "img-responsive" class. You do not need col-sm-4, col-md-4, col-lg-4 if you intend to have the 3 columns on all screen sizes.

<div class="container">
<div class="row">
    <div class="col-xs-4">
        <img src="http://placehold.it/350x250" id="picture1" class="img-responsive" />
    </div>
    <div class="col-xs-4">
        <img src="http://placehold.it/350x250" id="picture2" class="img-responsive" />
    </div>
    <div class="col-xs-4">
        <img src="http://placehold.it/350x250" id="picture3" class="img-responsive" />
    </div>
</div>

like image 31
sevmusic Avatar answered Oct 31 '22 19:10

sevmusic