From a recent post on the Twitter Bootstrap google plus community, the correspondent wanted to know how to make a sidebar move under a navigation bar in a layout, like so:

The following jsfiddle explains how pretty well:

(Note that there’s no Javascript in the fiddle, click on the HTML, CSS, and result.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div class="container">
  <div class="row">
    <div class="col-xs-12 col-md-8">
      <div class="well one">1</div>
    </div>
    <div class="col-xs-12 col-md-4">
      <div class="well two">2</div>
    </div>
    <div class="col-xs-12 col-md-8">
      <div class="well three">3</div>
      <div class="well four">4</div>     
    </div>
  </div>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css');

/*
  this is the magic right here - the media query for screen size that
  only floats the particular divs to the right. 
*/
@media screen and (min-width: 970px) {
    .col-md-8{
        float:right 
    }
}
.one{
    min-height: 200px;
}
.two{
    min-height: 800px;
}
.three{
    min-height: 400px;
}
.four{
    min-height: 300px;
}

The way this works is to set up the various column options in TBS for your divs. In the medium format, col-md-8 gets floated to the right side of the page. Since there are two divs that get set that way, when the page is narrowed the col-md-8 goes out of play and the col-xs-12 goes into play, reordering the stack.

Pretty cool solution, actually.