Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap add margin to column

This is probably very simple, but my mind is getting tangled with trying to work this out. Spent an hour or so searching this up and it still isn't working.

My HTML code...

<div class="section-container light-bg">
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h2 style="text-align:center;">Main Title Right Here</h2>
            <h4 style="text-align:center;">Slogan text underneath</h4>
        </div>
        <div class="col-md-3 light-panel">
            <h3>TITLE</h3>
            <p>TEXT</p>
        </div>
        <div class="col-md-3 light-panel">
            <h3>TITLE</h3>
            <p>TEXT</p>
        </div>
        <div class="col-md-3 light-panel">
            <h3>TITLE</h3>
            <p>TEXT</p>
        </div>
        <div class="col-md-3 light-panel">
            <h3>TITLE</h3>
            <p>TEXT</p>
        </div>
    </div>
</div>

CSS

.section-container.light-bg {
    background-color: #F5F5F5;
    color: #444444;
}

.section-container .light-panel {
    background-color: #ffffff;
    border-radius:10px;
}

This is currently creating a row with 4 columns that are styled slightly.

Any help or explanation of how to correctly do this using Bootstrap 3 would be greatly appreciated :)

like image 450
user282076 Avatar asked Apr 04 '14 10:04

user282076


People also ask

How do I add a margin between Bootstrap columns?

To add space between columns in Bootstrap use gutter classes. With gutters you can add horizontal or vertical space or even specify how big space should be on different screen size.

How do you add a column margin?

Change margins and column guides Open the Pages panel (Window > Pages) and select the thumbnails for the pages you wish to change. Choose Layout > Margins and Columns. Enter values for Top, Bottom, Left, and Right Margins, as well as the number of columns and the gutter (the space between columns).

How do I add a margin to a Bootstrap row?

If you need to separate rows in bootstrap, you can simply use . form-group . This adds 15px margin to the bottom of row.

How do I set margins in Bootstrap 5?

t - for classes that set margin-top or padding-top. b - for classes that set margin-bottom or padding-bottom. s - (start) for classes that set margin-left or padding-left in LTR, margin-right or padding-right in RTL. e - (end) for classes that set margin-right or padding-right in LTR, margin-left or padding-left in RTL.


1 Answers

Demo Fiddle

The best approach is to add an inner container, then padding on the columns. This ensures Bootstraps functionality remains as intended.

HTML

<div class="section-container light-bg">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                 <h2 style="text-align:center;">Main Title Right Here</h2>

                 <h4 style="text-align:center;">Slogan text underneath</h4>

            </div>
            <div class="col-md-3 light-panel">
                <div class='inner'>
                    <h3>TITLE</h3>

                    <p>TEXT</p>
                </div>
            </div>
            <div class="col-md-3 light-panel">
                <div class='inner'>
                     <h3>TITLE</h3>

                    <p>TEXT</p>
                </div>
            </div>
            <div class="col-md-3 light-panel">
                <div class='inner'>
                    <h3>TITLE</h3>

                    <p>TEXT</p>
                </div>
            </div>
            <div class="col-md-3 light-panel">
                <div class='inner'>
                    <h3>TITLE</h3>

                    <p>TEXT</p>
                </div>
            </div>
        </div>
    </div>

CSS

 .section-container.light-bg {
    background-color: #F5F5F5;
    color: #444444;
}
.inner {
    background-color: #ffffff;
    border-radius:10px;
    padding:10px;
}
.col-md-3 {
    padding:10px;
}

Alternatively

You can use calculated width/margins., no change to your HTML necessary.

E.g. the width of col-md-3 is 100/4=25%. Therefore you can reduce this, say to 20%, and allocate the remaing 5% to your margins.

.col-md-3 {
    width:20%;
    margin:0 2.5%;
}
like image 189
SW4 Avatar answered Oct 24 '22 18:10

SW4