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?
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.
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.
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 .
If you need to separate rows in bootstrap, you can simply use . form-group . This adds 15px margin to the bottom of row.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With