Skip to main content
kineticcreative123
Inspiring
September 13, 2023
Answered

Need help with div stacking order

  • September 13, 2023
  • 1 reply
  • 2500 views

Hi everyone,

I am trying to chage the stacking order for some div's with text and images on mobile. They are side by side in rows of two. I uploaded screen shots of desktop and mobile of what I have currently. When stacking on mobile they stack with text-text-image-image and so on. I would like them to be text-image-text-image, etc. 

This is the link to my site I coded it and am hosting it in Marketo as a landign page:
https://offers.premierinc.com/Transforming-Healthcare

BTW-I removed what I tried in order not to confuse so basically I'm starting over with this post. 

I found this on stackeoverflow but can't get it to work with my code. 

.col {
  display: flex;
  flex-wrap: wrap;
}

.col div {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100px;
  width: 200px;
  border: 2px solid green;
  font-size: 18px;
}


/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {
  .col div:nth-child(1) {
    order: 1;
  }
  .col div:nth-child(2) {
    order: 2;
  }
  .col div:nth-child(3) {
    order: 4;
  }
  .col div:nth-child(4) {
    order: 3;
  }
}
<div class="col">
  <div class="text">.text column</div>
  <div class="img">.image column</div>
  <div class="text">.image column</div>
  <div class="img">.text column</div>

</div>

 

I've attached screenshots for someone to view.  

This is the code block in question with the div's I need to stack in bold. 

<section class="about-us-area section-padding-0-100 clearfix">
        <div class="container">
            <div class="row align-items-center">
 
                <div class="col-12 col-lg-6 ">
                    <div class="who-we-contant">
                        <div class="dream-dots text-left fadeInUp" data-wow-delay="0.2s" style="visibility: visible; animation-delay: 0.2s; animation-name: fadeInUp;">
                            <img src="https://offers.premierinc.com/rs/381-NBB-525/images/noun-pills-1104684.svg" width="50px"alt="">
                        </div>
                        <h4 class="fadeInUp" data-wow-delay="0.3s">Continuum of Care</h4>
                        <p class="fadeInUp" data-wow-delay="0.4s">Premier is supporting healthcare providers on the care continuum with
a dedicated purchasing program and experts, technology-driven supply chain tools, artificial intelligence (AI)-backed surveillance solutions and by advocating for necessary legislative reform. 
</p><a class="btn dream-btn mt-30 fadeInUp" data-wow-delay="0.6s" href="#">Read More</a>
                    </div>
                </div>
 
                <div class="col-12 col-lg-6">
                    <div class="welcome-meter fadeInUp" data-wow-delay="0.7s">
                        <img src="https://offers.premierinc.com/rs/381-NBB-525/images/about12.png" class="center-block" alt="">
                    </div>
                </div>
            </div>
        </div>
    </section>
 

Thanks for any help with this. 

    This topic has been closed for replies.
    Correct answer Nancy OShea

    Imagine the natural order on mobile is this:

    <div class="row">
        <div class="col> Child 1 </div>
        <div class="col> Child 2 </div>
        <div class="col> Child 3 </div>
        <div class="col> Child 4 </div>
    </div>
    
    

     

    But you want to rearrange the visual order on large devices to this:

    Child 2 | Child 1

    Child 4 | Child 3

     

    <div class="row">
        <div class="col order-lg-2"> Child 1 </div>
        <div class="col order-lg-1"> Child 2 </div>
        <div class="col order-lg-4"> Child 3 </div>
        <div class="col order-lg-3"> Child 4 </div>
    </div>

     

    I hope that makes sense.

     

    1 reply

    Nancy OShea
    Community Expert
    Community Expert
    September 13, 2023

    To be honest, I don't think it matters a whole hill of beans which comes first in the vertical order DOM given how mobile users swipe their devices up & down to find content.

     

    That said, you need to think about vertical order DOM when you plan your content because Bootstrap and other responsive frameworks are mobile-first.

    1. Reorder content <divs> precisely the way you want it in mobile DOM.  DO NOT use floated text & images for this. Keep text and images in separate <div>.

    2. Add Bootstrap order classes to rearrange <divs> on large devices.  Refer to Bootstrap 5 order-classes below for working examples.

    https://getbootstrap.com/docs/5.0/layout/columns/#order-classes

     

    Hope that helps.

     

     

    Nancy O'Shea— Product User & Community Expert
    kineticcreative123
    Inspiring
    September 13, 2023

    Thanks so much Nancy. I had no idea Bootstrap had that built in. So easy! One problem though now desktop is not stacking correctly they should be like below rotating back and forwarth. Also attached is what desktop is doing now. Thanks again for taking the time to reply.

     

     

    This is what it looks like now

     

    Nancy OShea
    Community Expert
    Nancy OSheaCommunity ExpertCorrect answer
    Community Expert
    September 14, 2023

    Imagine the natural order on mobile is this:

    <div class="row">
        <div class="col> Child 1 </div>
        <div class="col> Child 2 </div>
        <div class="col> Child 3 </div>
        <div class="col> Child 4 </div>
    </div>
    
    

     

    But you want to rearrange the visual order on large devices to this:

    Child 2 | Child 1

    Child 4 | Child 3

     

    <div class="row">
        <div class="col order-lg-2"> Child 1 </div>
        <div class="col order-lg-1"> Child 2 </div>
        <div class="col order-lg-4"> Child 3 </div>
        <div class="col order-lg-3"> Child 4 </div>
    </div>

     

    I hope that makes sense.

     

    Nancy O'Shea— Product User & Community Expert