Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in Bootstrap to "split" a column on small screens?

I'm using Bootstrap 3. On large screens I want to have a sidebar on the left and the maincontent on the right. On small screens I want to have important blocks of the sidebar on top, then the maincontent, then the less important blocks of the sidebar. Is there a way to achieve that?

Here's a JS Bin showing the problem: http://jsbin.com/wibucopi/1/ and below is the current code (which, however, displays all sidebar content on top on small screens).

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3">
      <div class="upper" style="background:red">
        <h3>I want to be <b>above</b> the main content on small screens!</h3>
      </div>
      <div class="lower" style="background:green">
        <h3>I want to be <b>below</b> the main content on small screens!</h3>
      </div>
    </div>
    <div class="col-sm-9">
      <h1>Main content</h1>
      <p>Lorem ipsum dolor sit amet</p>
    </div>
  </div>
</div>

I've already played around with col-sm-pull/push-x, but I could only achieve that the whole sidebar is displayed below the maincontent on small screens.

I don't want to duplicate content and show / hide it with visible-XY, hidden-XY, as the page would get bigger and it feels just wrong.

It would be great to have a pure Bootstrap css solution, or at least a css only one (I wouldn't like to use js).

like image 296
Christian Avatar asked Jul 28 '14 07:07

Christian


People also ask

How do I split a column into two rows in Bootstrap?

The column of a list can be split into rows using the grid system of BootStrap. The 'row' and 'col' classes of BootStrap enables splitting any area into rows and columns.

How do you write a grid system for a small device?

Bootstrap Grid - Small Devices Tip: Small devices are defined as having a screen width from 768 pixels to 991 pixels. For small devices we will use the . col-sm-* classes. Now Bootstrap is going to say "at the small size, look for classes with -sm- in them and use those".

How do I split a box in Bootstrap?

There is a container <div class="row"> and half width two divs in that ( <div1> and <div2> ). The <div1> 's height would be changeable as content size. And again, the <div2> should have two child divs( <div2-1>, <div2-2> ) that half height of <div1> each.

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

Using “div” tag: Simply adding a “div” with padding in between two “div” tags gives spacing between the “div”.


1 Answers

You could do something like this:

Bootply Demo

HTML:

<div class="container-fluid">
  <div class="row">
    <div class="upper col-sm-3" style="background:red">
      <h3>I want to be <b>above</b> the main content on small screens!</h3>
    </div>
    <div class="col-sm-9 col-sm-pull-right">
      <h1>Main content</h1>
      <p>Lorem ipsum dolor sit amet</p>
      <p>Lorem ipsum dolor sit amet</p>
      <p>Lorem ipsum dolor sit amet</p>
      <p>Lorem ipsum dolor sit amet</p>
      <p>Lorem ipsum dolor sit amet</p>
    </div>    
    <div class="lower col-sm-3" style="background:green">
      <h3>I want to be <b>below</b> the main content on small screens!</h3>
    </div>
  </div>
</div>

CSS:

@media (min-width: 768px) {
  .col-sm-pull-right {
      float: right;
  }
}
.lower {
  clear: left;
}
like image 196
jme11 Avatar answered Oct 19 '22 16:10

jme11