Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap: Multiple nested rows within row?

I know you can nest rows within nested columns, but is it 'against the rules' to nest rows directly within rows?

eg:

<div class="row">

  <div class="row">
     cols in here
  </div>

  <div class="row">
     cols in here
  </div>

  <div class="row">
     cols in here
  </div>

</div>

Or must these always be within columns?

like image 447
MeltingDog Avatar asked Sep 07 '15 07:09

MeltingDog


People also ask

Can I make row inside row in Bootstrap?

You can also pair each of them in rows, but you don't need to. Bootstrap wraps by default so you don't have to clutter your markup with new rows. If it's semantically meaningful, I'd say go for it. But if you're just displaying a list of 4 objects, keep them in the same row.

Is nested columns possible with Bootstrap grid system?

You can nest columns once you have a container, row, and column set up. To do this, add a new row <div> within the parent column's code, then add your nested columns. It will function as if the area inside the new row is its own grid system.

What is Col SM 4 in Bootstrap?

col-sm-4 are available for quickly making grid layouts. Columns create gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via negative margin on .

How do you put a space between two rows in Bootstrap?

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


1 Answers

is it 'against the rules' to nest rows directly within rows?

Not against the rules as such, but not a best practice as per the guidelines.

Per bootstrap guidelines, third point under introduction -

..and only columns may be immediate children of rows".

*Edit: This is still true with Bootstrap 4.0 Beta. The link to the docs above will automatically redirect to the version 3.3 documentation. Thank you @Aakash for pointing this out.

This is because of the padding which Bootstrap uses for its layout, it is a good practice to nest via row-column-row pattern i.e. nest a row with one column across to nest.

See the difference in the snippet below. The first set of markup breaks the Bootstrap layout, although nothing bad happens.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <div class="row">
      <div class="col-xs-6">One</div>
      <div class="col-xs-6">Two</div>
    </div>
  </div>
</div>
<hr>
<div class="container">
  <div class="row">
    <div class="col-xs-12">
      <div class="row">
        <div class="col-xs-6">One</div>
        <div class="col-xs-6">Two</div>
      </div>
    </div>
  </div>
</div>
<hr>
<div class="container">
  <div class="row">
    <div class="col-xs-12">One</div>
    <div class="col-xs-12">Two</div>
    <div class="col-xs-12">Three</div>
  </div>
</div>
like image 114
Abhitalks Avatar answered Oct 06 '22 01:10

Abhitalks