Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3.0:responsive column resets section of the documentation

Hey so in the bootstrap 3.0 documentation if you look under the subheading "responsive column resets" it says the following:

"With the four tiers of grids available you're bound to run into issues where, at certain breakpoints, your columns don't clear quite right as one is taller than the other. To fix that, use a combination of a .clearfix and our responsive utility classes."

Now what do they mean by this? I thought floats cleared-or didn't-based on width. What am I missing here?

like image 970
Demetrio M. Avatar asked Oct 04 '13 02:10

Demetrio M.


People also ask

How do we manually reset the column in Bootstrap to provide responsiveness?

The Bootstrap documentation recommends using what they call a responsive column reset. By adding a clearing div between rows, it'll guarantee that each new row will begin flush against the left edge.

Are Bootstrap columns responsive?

Bootstrap includes predefined classes for creating fast, responsive layouts. With six breakpoints and a dozen columns at each grid tier, we have dozens of classes already built for you to create your desired layouts.

What does Col-SM-4 mean?

col-sm-4 applies to small, medium, large, and extra large devices, but not the first xs breakpoint). You can use predefined grid classes (like . col-4 ) or Sass mixins for more semantic markup.

What does Col MD 5 class means?

col-md- stands for column medium ≥ 992px. col-xs- stands for column extra small ≥ 768px. The pixel numbers are the breakpoints, so for example col-xs is targeting the element when the window is smaller than 768px(likely mobile devices)...


1 Answers

I believe the example on http://getbootstrap.com/css/#grid-responsive-resets is wrong and not illustrating the problem.

The example on http://getbootstrap.com/css/#grid-responsive-resets not visual illustrating the problem.

your columns don't clear quite right as one is taller than the other

example without clearfix:

<div class="row">
  <div class="col-xs-6 col-sm-3" style="background-color:red;height:40px;">.col-xs-6 .col-sm-3</div>
  <div class="col-xs-6 col-sm-3" style="background-color:blue;">.col-xs-6 .col-sm-3</div>
  <div class="col-xs-6 col-sm-3" style="background-color:green;">.col-xs-6 .col-sm-3 (left)</div>
  <div class="col-xs-6 col-sm-3" style="background-color:yellow;">.col-xs-6 .col-sm-3 (right)</div>
</div>

On the extra small (xs) with the first column (red) taller then the second (blue )will cause the third (green) column float on the right side of the first too.

without clearfix

enter image description here

with clearfix

<div class="row">
  <div class="col-xs-6 col-sm-3" style="background-color:red;height:40px;">.col-xs-6 .col-sm-3</div>
  <div class="col-xs-6 col-sm-3" style="background-color:blue;">.col-xs-6 .col-sm-3</div>
  <div class="clearfix visible-xs"></div>
  <div class="col-xs-6 col-sm-3" style="background-color:green;">.col-xs-6 .col-sm-3 (left)</div>
  <div class="col-xs-6 col-sm-3" style="background-color:yellow;">.col-xs-6 .col-sm-3 (right)</div>
</div>

enter image description here

col-*-12

The problem happens also when you add more the 12 columns in a row and one of this rows should be 100% (col-*-12).

Consider this situation:

On the larger grids you want:

1 | 2 | 3
On the xs grid you want:
1 | 2
  3 

You can accomplish the above with:

Without clearfix:
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-4">1</div>
<div class="col-xs-6 col-sm-4">2</div>
<div class="col-xs-12 col-sm-4" style="background-color:red;">3</div>
</div>
</div>  

The red background will show you the last column will overlap the first. Adding the clearfix will remove this background:

With clearfix:  
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-4">1</div>
<div class="col-xs-6 col-sm-4">2</div>
<!-- Add the extra clearfix for only the required viewport -->
  <div class="clearfix visible-xs"></div>
<div class="col-xs-12 col-sm-4" style="background-color:red;">3</div>
</div>
</div>  

The results:

enter image description here

The overlap mentioned will be cause by the col-12-* classes don't have a float left, see also: https://github.com/twbs/bootstrap/issues/10152

On https://github.com/twbs/bootstrap/issues/10535 you will find an other illustration. This fiddle shows how the clearfix will solve the problem. Note <div class="col-sm-3"> here don't have a col-12-*. On the xs grid columns are 100% by default and don't have a float so col-xs-12-* will act the same as having non class on the xs grid.

like image 94
Bass Jobsen Avatar answered Oct 01 '22 00:10

Bass Jobsen