Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Bootstrap col and row classes on single element

one:

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

two:

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

Is both the implementations are same?can i use the 2 method so that i can reduced the mark-up.

like image 361
mask man Avatar asked Jan 06 '15 10:01

mask man


People also ask

Can you have a row in a column Bootstrap?

You can easily nest grids using bootstrap by adding additional rows. Here is a step-by-step guide for this process. Within the desired column, create another element with class row . This second row element will contain your nested grid.

How do I center a column in a row in Bootstrap?

The first approach uses bootstrap offset class. The key is to set an offset equal to half of the remaining size of the row. So for example, a column of size 2 would be centered by adding an offset of 5, that's (12-2)/2.

How do I split a row into two columns in Bootstrap?

You can use col-md-* class for child element inside the parent row class to split the columns for your need.


1 Answers

According to Bootstrap's own API documentation, when nesting columns any columns .col should be nested within a .row. The two should not be combined on a single element.

Aside from the fact this makes more sense semantically- the underlying CSS properties both classes affect are reliant on this structure.

Also note, when using col-md-12 in isolation, you are effectively creating a full width element (which a row is anyway). In which case using the grid layout may not be relevant unless you have other elements showing/coming into play at different screen sizes.

Right (if using other columns as well as col-md-12):

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

Wrong:

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

If you just want a full width element, you dont need to use the grid layout and/or can remove one level of nesting.

like image 155
SW4 Avatar answered Sep 22 '22 22:09

SW4