Arranging divs in a responsive grid layout for mobile screens

I am utilizing the Bootstrap Grid System, as shown in this example: Grid System

On mobile display, the ".col-12 .col-md-8" always appears in the first row.

Currently: .col-12 .col-md-8

.col-6 .col-md-4

How can I rearrange it so that ".col-6 .col-md-4" is displayed first?

.col-6 .col-md-4

.col-12 .col-md-8

Any help would be appreciated! Thank you!

Answer №1

Utilizing the CSS "Order" property in conjunction with a media query allows for easy re-ordering of columns on smaller screens when they are stacked.

Here's an example:

@media only screen and (max-width: 768px) {
    #first {
        order: 2;
    }
    #second {
        order: 4;
    }
    #third {
        order: 1;
    }
    #fourth {
        order: 3;
    }
}

If you want to tailor this technique to your column classes like .col-6, avoid applying it globally to the entire site to maintain flexibility. This is why I used ID's such as #first.

Answer №2

To easily reorder elements in your layout, just use the bootstrap order classes:

.col-12 .col-md-8 .order-2

.col-6 .col-md-4 .order-1

or

.col-12 .col-md-8 .order-last

.col-6 .col-md-4 .order-first

For more information, check out the official link: https://getbootstrap.com/docs/4.0/layout/grid/#reordering

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

CSS sibling causing a shift in an absolutely positioned div

Check out this example http://jsfiddle.net/4cu8m/ <div id="main1"> <div id="inner1"</div> <div id="inner2"</div> </div> The positioning of inner1 and inner2 in the CSS are identical. They are both absolutely ...

Showing text following a specific number of search outcomes

When pulling products from my database for a search page query, I need to include some specific text after the 6th and 12th pagination results on each page. If there are fewer than 12 results, the text should only appear after the 6th result. How can I imp ...

"The 'BillInvoice' object must be assigned a primary key value before it is ready for this relationship" - Error Message

There is an issue in my Django project related to the creation of a BillInvoice and its associated BillLineItem instances. The error message I'm receiving states: "'BillInvoice' instance needs to have a primary key value before this re ...

<fieldset> triggering onChange event in React form

I am facing an issue with my React component where multiple onChange functions are not getting fired. After some debugging, I realized that the problem lies with the fieldset element within the form. Removing the fieldset allows all onChange functions to w ...

problem with arranging photos and captions

When viewing this page in a narrow browser window, an issue arises with how the photo captions are displayed at the bottom of the page. It's evident that the caption extends past the right edge of the photo. My preference would be for the photo and c ...

Fade out a div with jQuery when hovered over, while preventing the links within the div

I've been experimenting with using jQuery to create a fade effect on a div when hovered over. However, I'm encountering an issue where the anchor link within the div cannot be selected once it is shown. $('#show').hover(function() { ...

I can't figure out why my CSS transition isn't functioning properly in React 18

I've attempted multiple times to implement a transition on eventBody, but it still isn't functioning correctly. Here's the snippet of code: export function Event({ event }: EventProps) { const [showDropDown, setShowDropDown] = useStat ...

What is the best way to define a variable that captures and logs the values from multiple input variables?

Hey there, I'm a new coder working on a shopping list app. I'm trying to display the input from three fields - "item", "store", and "date" - at the bottom of the page as a single line item. I attempted to do this by creating a variable called "t ...

Spacing between Div tags

Struggling with a tricky HTML cross-browser problem. The site was built by multiple people, making it quite messy, but needs to go live as soon as possible! Each of the 4 page layouts on the site are different and handled by separate classes. However, whe ...

Is it possible to personalize CSS properties using PHP sessions?

Currently, I am a beginner in PHP and enrolled in a technical school class to learn more about it. Our latest assignment involves using sessions to modify four CSS properties: body background-color, a:link color, a:hover color, and h1 color. The task inclu ...

Obtaining real-time stock information for the website

I am in the process of designing a dynamic homepage that will feature real-time stock charts and a screening function for various indicators. To achieve this, I will need access to live stock data from thousands of companies. It is crucial that this data i ...

Angular and Ionic collaborate by using ngFor to pass on the item.id during a (click) event

I have a list of items and I want to dynamically change the height of a card when I click on a button that is located on the card. Can anyone guide me on how to achieve this? I attempted to pass the item.id through a click event and use the id in a functi ...

Android Font Icon Spacing Issue with IconFont (Fontastic)

After using Fontastic.me to create an iconfont, I encountered an issue specifically with the native browser of Android 4.2.2 and 4.3 (such as modern Samsung tablets). In these browsers, the characters in the entire font appear to have no width. This proble ...

Html page only visible to authorized users

Is there a way to upload an html file to my website without making it visible to everyone? I don't want search engines like Google or Bing or any web spider to index it. I don't want to password protect it either. I just want it to be truly invis ...

Having trouble getting Bootstrap CSS to load in an .ejs file?

I am new to ejs and Node.js. I have a Node.js file. Whenever the localhost receives a get request, I redirect to the index.ejs file. The data is displayed in the browser, but the CSS is not loaded. Can someone help me identify the issue in this code? I hav ...

Achieving Title Alignment in PDF Export with Balkan OrgChartJS

function preview() { /*centerElement();*/ let fileNameWithTitle = MyTitle.replace(/\s+/g, '_'); let PdfTitle = "<center>" + MyTitle + "</center>"; OrgChart.pdfPrevUI.show(chart, { forma ...

I'm unable to select a checkbox using Python Selenium

My attempt to create a checkbox using Python Selenium resulted in an error message. selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable I believe the issue lies with the element, but I am unsure of its exact locat ...

Is there a way to modify the color of a specific section of a font icon?

Currently, I am in the process of implementing an upvote button using fa fa signs. However, I have encountered an issue where the background color of the up vote button is bleeding outside of the sign (possibly due to padding on the icon), and I am strivin ...

Initiate an "ENTER" command through programming

Is it possible to automatically trigger the "Enter" keypress after a value is added to an input text box? If so, I am in need of assistance with my current code, as it does not seem to be working correctly. Here is the code snippet: $('#clo_cart&ap ...

Dropdown menu remains unable to open

One of the dropdown menus on my website is not retracting back properly, but only on the contact page where a Google map is displayed. The issue looks like this: I've tried tweaking the CSS code without success. What could I be missing? Should I prov ...