Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the order of col-*-12 columns in Bootstrap using push/pull

I have two columns of the same size (.col-xs-12) and I would change their place when the screen size correspond to that of a mobile device. I would place them in the reverse order.

I have read that push and pull bootstrap directives help to accomplish that, but is it possible to change the place of two columns of the same size with the following classes?

div.col-xs-12.col-xs-push-12   p test1 div.col-xs-12.col-xs-pull-12   p test2 
like image 884
Mazzy Avatar asked Sep 07 '14 21:09

Mazzy


People also ask

How do I change the order of columns in Bootstrap?

We can easily change the order of built-in grid columns with push and pull column classes. The Push and Pull Classes: The push class will move columns to the right while the pull class will move columns to the left.

How do I change the order of columns in Bootstrap 4?

Since Bootstrap 4 is flexbox, it's easy to change the order of columns. The cols can be ordered from order-1 to order-12 , responsively such as order-md-12 order-2 (last on md , 2nd on xs ) relative to the parent . row . It's also possible to change column order using the flexbox direction utils...

How do I change the order of elements in Bootstrap?

You can order the elements using a flex container. The outer div is set to "display: flex;" and the inside elements get given an order. By giving element B an order of 1, and element A an order 2. Element B will be placed before A even though A is first in the code.

What is Col XS 12 in Bootstrap?

col-lg- stands for column large ≥ 1200px. 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

Actually you can not reorder the columns having .col-*-12 by push/pull helper classes. The sum of columns exceeds the default 12 columns which is defined by @grid-columns.

You could either change the order of columns in HTML and then use the ordering classes on larger screens as follows:

EXAMPLE HERE

<div class="row">   <div class="col-xs-12 col-sm-6 col-sm-push-6">     <p>test2</p>   </div>    <div class="col-xs-12 col-sm-6 col-sm-pull-6">     <p>test1</p>   </div> </div> 

Or use this fancy approach to reverse the ordering of the columns that are placed vertically under each other:

EXAMPLE HERE

@media (max-width: 767px) {   .row.reorder-xs {     transform: rotate(180deg);     direction: rtl; /* Fix the horizontal alignment */   }    .row.reorder-xs > [class*="col-"] {     transform: rotate(-180deg);     direction: ltr; /* Fix the horizontal alignment */   } } 

It's worth noting that CSS transforms are supported in IE9 as well; Just don't forget to add vendor prefixes.

like image 120
Hashem Qolami Avatar answered Oct 02 '22 18:10

Hashem Qolami