60

I have the following layout on a page:

<div class="col-lg-3">1</div>
<div class="col-lg-2">2</div>
<div class="col-lg-2">3</div>
<div class="col-lg-2">4</div>
<div class="col-lg-3">5</div>

 --------- ----- ----- ----- ---------
|    1    |  2  |  3  |  4  |    5    |
 --------- ----- ----- ----- ---------

But on smaller screen sizes I would like the following layout:

<div class="col-xs-6">1</div>
<div class="col-xs-6">5</div>
<div class="col-xs-4">2</div>
<div class="col-xs-4">3</div>
<div class="col-xs-4">4</div>

 ----------------- -----------------
|        1        |        5        |
 ----------------- -----------------
|     2     |     3     |     4     |
 ----------- ----------- -----------

(Note the re-arranging of the column order.) Is it possible to push/pull columns only on smaller screen sizes? I've tried the following, but I get the oddest layout, and seem to lose <div>5</div> completely...:

<div class="col-lg-3 col-xs-6">1</div>
<div class="col-lg-2 col-xs-4 col-xs-push-4">2</div>
<div class="col-lg-2 col-xs-4>3</div>
<div class="col-lg-2 col-xs-4>4</div>
<div class="col-lg-3 col-xs-6 col-xs-pull-12">5</div>

2 Answers 2

158

Answered it myself, simply by thinking: mobile first!

<div class="col-lg-3 col-xs-6">1</div>
<div class="col-lg-3 col-xs-6 col-lg-push-6">5</div>
<div class="col-lg-2 col-xs-4 col-lg-pull-3">2</div>
<div class="col-lg-2 col-xs-4 col-lg-pull-3">3</div>
<div class="col-lg-2 col-xs-4 col-lg-pull-3">4</div>

Get them in the order I want on the tablet first, then push/pull them in to position on the desktop.

2
  • 16
    Yep, that's the right way to do it, since Bootstrap (3) is itself mobile-first.
    – zessx
    Feb 21, 2014 at 16:39
  • 1
    Today I learn my lesson with boostrap... Think mobile first. Thanks!
    – equiman
    Jun 6, 2016 at 21:20
5

I had a slightly different requirement (still in the similar lines)

the below gets me there:

<div class="row">
    <div class="col-lg-1 col-xs-2">TIME</div>
    <div class="col-lg-5 col-xs-6">EVENT</div>
    <div class="col-lg-2 col-xs-4">STATUS</div>

    <div class="col-xs-2 visible-xs"></div> @*offset for xs*@

    <div class="col-lg-2 col-xs-6">START LIST</div>
    <div class="col-lg-2 col-xs-4">RESULTS</div>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.