Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reverse the order of columns in Bootstrap 4?

I have this simple scenario:

<div class="row">     <div class="col-md-12 col-lg-6 col-xl-7">A</div>     <div class="col-md-12 col-lg-6 col-xl-5">B</div> </div> 

basically if md

A B 

I would like it, if md

B A 

I have tried many variants found on web, like flex-first and whatnot.. can't seem to get it to work

Any ideas?

like image 860
Patrioticcow Avatar asked Oct 10 '17 17:10

Patrioticcow


People also ask

How do I reverse a column in Bootstrap 4?

Use the flex-*-column-reverse class to display flex items vertically and reversed on different screen sizes.

How do I change the order of columns in Bootstrap?

Write the columns in an order, and show them in another one. You can easily change the order of built-in grid columns with . col-md-push-* and . col-md-pull-*modifier classes where * range from 1 to 11.

How do I reverse a div in Bootstrap?

Use the flex-row-reverse class in Bootstrap to reverse the order of flex items. It also aligns the flex items to the right.

How do I change the column order in Bootstrap 4 for mobile layout?

To do this, you would need to set the source code to be in the order you want it to be on mobile. Then add the order classes to the columns specifying the order at the breakpoint you choose. In our case we want SM and up. Using Bootstrap's order classes you can essentially move columns around like a forklift.


2 Answers

If you want to change order on md and larger sizes you can use order-md-, this is provided by bootstrap. It looks like, if you want to change order only on md size you will have to define normal order on one larger size Fiddle

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" />  <div class="row">    <div class="col-md-12 order-md-2">A</div>    <div class="col-md-12 order-md-1">B</div>  </div>
like image 63
Nenad Vracar Avatar answered Sep 24 '22 11:09

Nenad Vracar


It's also possible to use the flex- helper classes to solve this issue. This solution allows you to reverse the order without the order count on the columns.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" />  <div class="row flex-column-reverse flex-lg-row">    <div class="col-md-12 col-lg-6 col-xl-7">A</div>    <div class="col-md-12 col-lg-6 col-xl-5">B</div>  </div>

The flex-direction is now reversed by default (md) and will be overriden on the lg breakpoint.

like image 42
Tim Vermaelen Avatar answered Sep 21 '22 11:09

Tim Vermaelen