-2

I want to change the order based on if the user is on mobile or PC.

I want this order for mobile:

A

B

A

B

And this for PC:

A B

B A

What I tried so far:

<div class="row">
    <div class="col-sm-5 col-sm-pull-5">
        Content A
    </div>
    <div class="col-sm-5 col-sm-push-5">
        Content B
    </div>
</div>
<br><br>
<div class="row">
    <div class="col-sm-5 col-sm-push-5">
        Content A
    </div>
    <div class="col-sm-5 col-sm-pull-5">
        Content B
    </div>
</div>

The first row works fine, but the second row doesn't, and I can't see how to fix it. What is the best way to do this?

stijnb1234
  • 184
  • 4
  • 19
  • Have you tried to use the [order](https://getbootstrap.com/docs/4.0/utilities/flex/#order) flex property? The col-sm-5 class is fine, order-sm should be 1 (all in right order) and order-X on these elements telling CSS how should be columns ordered on SM-down devices. You should make these columns to be displayed as flex (.d-flex) and to be wrapper (.flex-wrap) – Johnczek Mar 22 '20 at 11:03

2 Answers2

1

I think I found your solution here. Try it:

<div class="row">
    <div class="col-md-5">
        Content A
    </div>
    <div class="col-md-5">
        Content B
    </div>
</div>
<br><br>
<div class="row">
    <div class="col-md-5 order-md-1">
        Content A
    </div>
    <div class="col-md-5 order-md-0">
        Content B
    </div>
</div>

in codesnipped you do not see the effect. you have to test it in a browser


SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
0

I found a solution, but I don't think it's the best way to do it:

<div class="row">
    <div class="col-sm-5 order-sm-0 order-lg-1">
        Content A
    </div>
    <div class="col-sm-5 order-sm-1 order-lg-0">
        Content B
    </div>
</div>
<br><br>
<div class="row">
    <div class="col-sm-5 col-sm-push-5">
        Content A
    </div>
    <div class="col-sm-5 col-sm-pull-5">
        Content B
    </div>
</div>
stijnb1234
  • 184
  • 4
  • 19
  • I think that using order property of flex boxes is perfectly fine solution. Order property of flex was designed exactly for this purpose. The only thing you should be aware is bad compatibility of IE. There might be some problems displaying the content like this in this fosile. – Johnczek Mar 22 '20 at 11:19