Last Updated: September 09, 2019
·
203
· csb324

Y'all, the bootstrap grid isn't compulsory.

If you're using bootstrap, there's no law saying you MUST put everything in a grid layout. This code:

<div class="row">
    <div class="col-md-12">
        <h1>hello</h1>
    </div>
</div>

is exactly the same as this:

<h1>hello</h1>

But I see the longer one all the time. Save yourself some time! Don't bother with this nonsense!

(There is a time and a place to use the col-*-12 classes, but most of the time they're not necessary)

2 Responses
Add your response

there necessary only when we need left and right padding

over 1 year ago ·

@jitendrav Well, only kind of. The div.row has negative margins that are equal to the padding on the columns. So if you're already inside a row (for the sake of some other grid-business somewhere else, and you can't get out), then yes, you need the column to offset that fact.

But if you aren't already inside a row, you don't need to create one only to counteract it with the column padding. And if you just want extra padding, don't create a row -- just put the column inside the container.

over 1 year ago ·