Rearrange the following <div> to appear before the previous one on medium and small devices using Bootstrap

I'm working with this div from the Bootstrap framework:

<div class="card-header py-md-0 py-lg-0 py-xl-0 pl-0 pr-0">
    <div class="d-flex justify-content-between align-items-center">
        <div class="h5 mb-0">Text text</div>
        <div class="text-right">
            <div class="actions">
                <a href="#" class="action-item"><i
                        class="far fa-heart mr-1"></i>
                    50</a>
                <a href="#" class="action-item"><i class="far fa-eye mr-1"></i>
                    250</a>
            </div>
        </div>
    </div>
    <p class="font-size-1">Text text text text text
    </p>
</div>

For medium and small devices, I need the second div with class="actions" to move above the first one and be aligned to the left.

I've attempted the following CSS code without success. Is there something crucial that I might be overlooking?

@media only screen and (max-width: 960px) {
  .col-xs-12 {
    display: flex;
    flex-direction: column-reverse;
  }
}

Any pointers or suggestions would be greatly appreciated. Thank you!

Answer №1

Assuming you are utilizing Bootstrap 4:

Bootstrap prioritizes mobile-first design, so the simplest approach is to structure the code starting from the .sm view, with the desired div placed first within the entire .row.

You can refer to this section in Bootstrap 4 for more information: https://getbootstrap.com/docs/4.4/layout/grid/#order-classes

To prioritize the display of the specific div on sm and md screens, you need to add .order-lg-2 to that div (remembering the mobile-first principle). Additionally, utilize Bootstrap classes like

.justify-content-[sm, md, lg]-[start, center, between, end, around]
to adjust its position. Adding .d-flex to the second div might also be necessary (this was effective in my project).

Below is an example of how I implemented this solution successfully (note that these sections were displayed side-by-side on lg+ screens, so column sizes may require adjustment):

<div class="container">
      <div class="row">
        <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 order-lg-2 justify-content-center justify-content-sm-start"> <!-- shows first on sm/md, 2nd on lg -->
           <!-- your code -->
        </div>
        <div class="col-xl-8 col-lg-8 col-md-12 col-sm-12 order-lg-1 justify-content-center justify-content-md-start"> <!-- shows 2nd on sm/md, 1st on lg -->
          <!-- more code -->
        </div>
      </div>
    </div>

Check out this CodePen demonstration I created to visualize how it operates: Codepen

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with functionality of Bootstrap template generated by Visual Studio 2013

I've set up a new ASP.NET MVC project using the latest Bootstrap 3 template, but I'm encountering an issue. There doesn't seem to be any spacing between the header navbar and the content displayed below by Renderbody(). I've attempted t ...

Looking to modify the styling of links in an unordered list?

Let me explain what I attempted to accomplish CSS: li:nth-child(2n) { background-color:gray; } HTML: <ul> <li><a></a></li> <li><a></a></li> <li><a></a></li> ...

Create an HTML table with a line separating two table cells

I need help with creating a table row and td's dynamically using basic HTML and CSS. I would like to draw lines between the td's similar to the example image shown below. Can someone please assist me in achieving this? https://i.sstatic.net/GPd ...

Is there a way to print an HTML page in Landscape mode within my Vue.js project?

I have been able to successfully print an HTML page in Landscape mode using the code below. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,maximum-scale=1.0"> ...

After applying CSS, I am unable to click on the radio buttons

Even after selecting the other two, it still defaults to the first one. Here is my code: input[type=radio] { display:none; } input[type=radio] + label:before { content: ""; display: inline-block; ...

concealing the upper header while scrolling and shifting the primary header upwards

Is there a way to use CSS to move the main header navigation, including the logo and links, on my website up when scrolling down in order to hide the top black bar header that contains contact information? The website in question is atm.truenorthmediasol ...

Mastering the art of column stacking with CSS on your WordPress website

Looking for a CSS solution to adjust the layout when the screen resolution is lowered. Currently, I have two rows with three columns in each row, containing blurbs. My goal is to make these two rows convert into three rows with two columns each at a cert ...

What is the best way to maintain the formatting of a textarea in the database?

My HTML form includes a text area and a functionality to save the data into a database upon submission. The issue arises when the saved data is retrieved from the database, as the original formatting of the text gets altered. For instance: "This is a text ...

What is the best way to showcase a blank div element using CSS?

Is there a way to make this empty div tag display without having to add &nbsp;? Can it be achieved using only CSS? <div class="bar bg-success" title="2015-07-23,5.0000" height="50%"></div> .bar { background: green; width: 5px; float ...

FireFox appears to be experiencing issues with accessing the contentDocument of a frame using jQuery

While this line of code functions correctly on Chrome and IE, it encounters an issue on FireFox. The error message displayed in the FireFox console is: ReferenceError: $ is not defined var lang = $($('#navFrame')[0].contentDocument).find('# ...

Can you explain the purpose of using "link href="#""?

While browsing through the source code of a website, I came across this interesting snippet. <link href="#" id="colour-scheme" rel="stylesheet"> I'm curious, what exactly does this code snippet do? ...

Trouble with image rotation in jQuery/JavaScript slideshow

For more information, you can visit and click on the Canucks icon, which is located as the third icon below "information architecture and usability." I am attempting to set up a jQuery slideshow by utilizing a template I found online. However, I am encou ...

Angular implementation of a dynamic vertical full page slider similar to the one seen on www.tumblr

I'm determined to add a full-page slider to the homepage of my Angular 1.x app After testing multiple libraries, I haven't had much luck. The instructions seem incomplete and there are some bugs present. These are the libraries I've experi ...

Resetting CSS animations using animation-delay

My aim is to animate a series of images on my landing page using Next.js and SCSS. The issue arises when I try to add dynamic animations that reset after each cycle. The delay in the animation causes the reset to also be delayed, which disrupts the flow. I ...

Alignment issue with text in Vuetify Datatables cells

I'm experimenting with Vuetify on my Laravel Vue application, and everything seems to be working fine except for the DataTables styles. The padding of the cells is not vertically center aligned as expected. Here's a screenshot Interestingly, the ...

What's the best way to ensure these have equal heights?

There seems to be a difference in height between the verses at the bottom, and I want each verse next to each other to have equal heights. Here is my current code setup: .verse img { height: 1em; } <h1>PSALM 1</h1> <p> <div> ...

Steps to resolve transition zoom issues with images

I'm having trouble showcasing blog posts with an image. Currently, I am utilizing card-columns from Bootstrap 4, and when the user hovers over the image, it scales up. The issue arises when the transition occurs, as my border radius resets to defaul ...

Error occurs when SRCSET loads the wrong size because "sizes" parameter is missing

According to the guidelines, when sizes is not specified in the image attribute, the browser should automatically calculate the required size based on CSS rendering. In this scenario, my image is 300px and the browser should select the 300px image. Howeve ...

html5 Showing and hiding div elements

Here is a snippet of code to consider: @using App.Models @model App.Models.AllPeopleViewModel @{ ViewBag.Title = "Index"; } <html> <head> </head> <body> @foreach (Customer person in Model.Content) { <div class=&qu ...

What could be the reason for my clickable div not functioning as a link in this particular code?

Here is my jQuery script: $('.projektet').click(function(){ var url = $(this).find("a").attr("href"); window.location = url; }); <div class='projektet'> <h3>".$alias." ".$expertis." ".$other."</h3> & ...