Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap 2: How to get responsive design to place sidebar on the bottom instead of top?

Twitter's Bootstrap 2 finally added native responsive design. However, by default when the browser width is below a min width, it places the sidebar on top. I can see how this would work for many sites, but I actually want the sidebar at the bottom on small width layouts.

I'm brand new to Twitter Bootstrap and tried to figure out what part of the CSS in bootstrap-response.css, but I didn't see anything in the section for @media (max-width: 480px).

I looked at the Bootstrap documentation for the responsive design and there isn't much detail on it.

Would love some pointers...

like image 459
TMC Avatar asked Feb 12 '12 02:02

TMC


People also ask

How to move sidebar in CSS?

Moving The Sidebar wrap element and all 3 columns. The top position for all 3 columns is set to 0, and then we stick the right sidebar to the right, move the left sidebar left -50% (negative the width of #main-content) and move the main content left 25% (the width of #left-sidebar) to rearrange the columns.

Is Bootstrap adaptive or responsive?

Bootstrap is built on responsive 12-column grids, layouts, and components.

How to span columns in Bootstrap?

First; create a row ( <div class="row"> ). Then, add the desired number of columns (tags with appropriate . col-*-* classes). Note that numbers in .

Is twitter bootstrap responsive?

With Bootstrap 2, we've gone fully responsive. Our components are scaled according to a range of resolutions and devices to provide a consistent experience, no matter what.


2 Answers

You can achieve this effect by flipping the containers for the sidebar and content area and just floating them the way you want to. This can be done cleanly without messing around too much with the bootstrap stylesheet by assigning your own ids to the sidebar and content area and doing something like this:

CSS

.sidebar-nav {
    padding: 9px 0;
    width:100%;
}

#sidebar {
    float:left;
    margin-left:0;
}

#content {
    float:right !important;
    margin-left:auto;
}

@media (max-width: 767px) {
    #sidebar {
        display: inline-block;
        margin-top: 20px;
        width: 100%;
    }

    #content {
        float:none !important;
        margin-left:0;
    }
}

Then all you have to do is flip the container divs like so:

<div id="content" class="span9"> ... </div> /* item you want up top first */
<div id="sidebar" class="span3"> ... </div> /* last item to be rendered below */

Demo: http://jsfiddle.net/andresilich/YEUwN/1/show/ Edit here: http://jsfiddle.net/andresilich/YEUwN/1/

like image 173
Andres Ilich Avatar answered Oct 07 '22 13:10

Andres Ilich


It might be easy.

// Pull right sidebar to top
<div class="row">
  <div class="span3 pull-right">Right sidebar</div>
  <div class="span9">Content section</div>
</div>

// Or pull left sidebar to bottom side
<div class="row">
  <div class="span9 pull-right">Content section</div>
  <div class="span3">Left Sidebar</div>
</div>
like image 30
xcono Avatar answered Oct 07 '22 15:10

xcono