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

implementing a fixed header in HTML

I am facing a challenge where I have a header with dynamic height and fixed position. My goal is to position the container div right below the header. However, since the header height varies, using a fixed value for margin-top is not feasible. Any sugges ...

What is the best way to arrange elements based on the numeric value of a data attribute?

Is there a way to arrange elements with the attribute data-percentage in ascending order, with the lowest value first, using JavaScript or jQuery? HTML: <div class="testWrapper"> <div class="test" data-percentage="30&qu ...

Unable to display the value of a server-side li element using JQuery

I am trying to retrieve values from a ul list that is populated from the database using server-side code. I want to display the li value in a jquery alert function, but it doesn't seem to be working as expected. Strangely, the same function works perf ...

Challenges with borders within a modal box

I am trying to create some spacing above and below the 'offer' button within my modal. Initially, I attempted to add a 30-pixel border to the bottom of the button, but it doesn't seem to be appearing. The end of the modal aligns directly wit ...

Is there a way to gather information from a web service and neatly display it within an HTML table?

Is it possible to fetch a JSON array from a web service and save it in a variable? Consider the following table structure: <table id="myTable" border="1"></table> The table is populated using the code below: // JSON array var myData = metho ...

What are the differences between incorporating JavaScript directly into HTML and writing it in a separate file?

I need help converting this JavaScript embedded in HTML code into a standalone JavaScript file. I am creating a toggle switch that, when clicked, should go to a new page after the transformation. I am looking for the non-embedded version of the function. H ...

Automatically adjust the top margin of the content section to accommodate a fixed header height

After extensive searching, I've come across various solutions but none of them seem to fit my needs. I am a beginner/amateur developer. The issue I am facing is with a fixed header that resizes when scrolling. I understand that by adding padding-top: ...

Styling elements with CSS to achieve proper positioning

I am in search of a way to align rows utilizing the style property. The following HTML code is being transformed using XSL: <span style="white-space: pre; font-size: 8pt; font-family: Lucida console, Courier ">&lt;40 : item1</span>&l ...

`Enter` within a container

Is there a way to use a controller in order to achieve printing test1 test2 within a <div> element... Currently, the only code I have is a simple Return "test1" & vbNewLine & "test2" However, this code displays the words on a single line ...

Navigate through the Jquery slider by continuously scrolling to the right or simply clicking

Is there a way to prevent my slider from continuously scrolling? I think it has something to do with the offset parameter but I'm having trouble figuring it out. Any assistance would be greatly appreciated. var $container = $(container); var resizeF ...

Is it possible to separate a portion of HTML into a template and reuse it in multiple locations within a webpage?

In my HTML, I have an issue with duplicate code. In Java, I typically use IntelliJ to mark the code and select "extract method" => "replace 2 occurrences". I am looking for a similar solution in HTML, but the current method seems messy: <ng-template #b ...

The Stripe card element seems to be missing from the form

I'm a newcomer to angularjs and currently working on integrating version 3 of the stripe api into my angular application. I followed the steps provided on the stripe website, but faced an issue when trying to incorporate their code which is primarily ...

Choosing elements in jQuery

Having some trouble with the subnav on my current website project. I think the issue lies in how I am selecting items in my jquery code. It seems like a small fix that needs to be made, but I'm unsure of the correct approach. http://jsfiddle.net/ZDEr ...

Looking for a Search Field that clears default text when focused - Compatible with Firefox 3.6?

I have attempted various jQuery and JavaScript solutions found on this page: How to clear text field on focus of text field Surprisingly, all of the solutions work except for FF 3.6. So, I am wondering, What alternative can I use to make this feature com ...

Difficulty with animated presentations

As a developer with limited CSS experience, I am trying to create a CSS3 slideshow using only two images. After discovering some interesting code for this purpose, which can be found here, I decided to make a small change to the original code (specifically ...

I am encountering an issue with opening a dropdown select option upon clicking in C# while using Selenium

I am encountering an issue while attempting to open the Register page from my account. The UI developer utilized Bootstrap code, and Bootstrap developers have included a JS function on click. However, when I execute this code, an error is thrown: "OpenQA.S ...

Animate your SVG with CSS using hover effects that originate from the center of the SVG

I successfully implemented this animation using GSAP and you can view the Codepen for reference: https://codepen.io/whitelionx/full/vYGQqBZ const svgs = document.querySelectorAll("svg"); svgs.forEach((svg) => { const tl = gsap .timelin ...

Is there a way to streamline the form completion process on my website by utilizing voice commands through the user's microphone?

My webpage features a web form using Flask where users manually input their information that is then added to a table upon submitting. The current setup involves an autoplay video prompting users with questions, which they answer manually and then submit t ...

Resize images in PHP and MySQL with precision without distorting the image

I'm looking for a solution to resize images on upload without deforming them. The current code uploads the image and stores it in the database, but I need to add resizing functionality. I'd prefer not to use JavaScript, but if necessary, please i ...

In a designated paragraph, set the display of all <span> elements to none using JavaScript

I have a long paragraph with over 10,000 lines of text and I need a way to quickly remove all the lines without hiding the entire paragraph. Specifically, I want to hide each line individually by changing the span style from "display:block" to "display:non ...