What is the best way to arrange divs in Bootstrap 4?

Is there a way to reorder two divs that are next to each other in a row on mobile? I want the right side div (col-md-9) to be displayed first.

I attempted using flex ordering, but unfortunately it caused layout issues throughout my site.

<div class="row">
   <div class="col-md-3">Left side</div>
   <div class="col-md-9">Right side, displayed first on mobile or tablet</div>
   <div class="clearfix"></div>
</div>

When viewing the site on mobile or tablet, I specifically want the col-md-9 div to be the first one shown.

Answer №1

@media screen and (max-width: 767px) {
  .col-md-3 {
    order: 2;
  }
  .col-md-9 {
    order: 1;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

<div class="row">
  <div class="col-md-3">Left side</div>
  <div class="col-md-9">Right side, but first on mobile or tablet</div>
  <div class="clearfix"></div>
</div>

Answer №2

If you want to reverse the order of a row, you can do so by adding a specific class. Below is an example code snippet for you to try:

<div class="row flex-row-reverse">
   <div class="col-md-9">Right side, but first on mobile or tablet</div>
   <div class="col-md-3">Left side</div>
   <div class="clearfix"></div>
</div>

Answer №3

Simply utilize the order property.

@media only screen and (max-width: 760px) {
  .col-md-3 {
 order:2;
  }
}

@media only screen and (max-width: 760px) {
  .col-md-3 {
 order:2;
  }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="row">
   <div class="col-md-3">Left side</div>
   <div class="col-md-9">Right side, but first on mobile or tablet</div>
   <div class="clearfix"></div>
</div>

Answer №4

Utilize Column Ordering to achieve this.

col-md-push-6 will move the column 6 spaces to the right, while col-md-pull-6 will shift it 6 spaces to the left on medium viewports and above. On smaller viewports, the columns return to their regular order.

The reason for confusion is that in your HTML code, B needs to be placed above A. There might be another method to arrange them where A comes before B in the HTML, but I'm not certain about how to execute it...

Check out Code Example

<div class="row">
  <div class="col-md-6 col-md-push-6">B</div>
  <div class="col-md-6 col-md-pull-6">A</div>
</div>

Viewport size greater than or equal to md

|A|B|

Viewport size less than md

|B|
|A|

Answer №5

Utilize the power of flex and order with the following example:

If this is causing issues across all sites, consider creating a custom class and applying CSS accordingly.

@media screen and (max-width: 531px) {
    .row { display: flex; flex-direction: column; }
    .two { order: 1; }
    .one { order: 2 }
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
<div class="row">
   <div class="col-md-3 one">Left side</div>
   <div class="col-md-9 two">Right side, but first on mobile or tablet</div>
   <div class="clearfix"></div>
</div>

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

Recommendation for a reliable and user-friendly chat platform without the need for third-party involvement

I am in need of a chat room for a specific group of users on my social network. Ideally, I want a chat feature that is simple and does not require a third party. The chat should automatically use the user's name based on their authorized id when they ...

The bootstrap navbar dropdown feature isn't functioning properly on iPhones

Currently utilizing "bootstrap": "~3.3.4" within the mean.js framework, I am facing an issue with the navbar dropdown menu. On desktop, everything functions as expected - the dropdown opens and remains open when the icon is clicked. However, once deployed ...

HTML5 document type declarations

After switching my site's doctype from XHTML to HTML5, I have made the following changes: I currently have: <!DOCTYPE html> <html lang="en-GB" xml:lang="en-GB" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> Now my question is, do I sti ...

Safari iOS does not display any background for Buttons

Encountering an unusual problem with buttons on iOS devices specifically in Safari browser - the background color isn't being applied like it is on Desktop and Android devices. Here are the CSS properties for the button: export const Button = styled.b ...

Exploring Web Scraping Through Dual System Security

I come seeking guidance on how to navigate a website with two different security systems in place. The first system requires a username and password, which I have successfully managed to handle. However, the second security system only requires a password ...

Is there a way to assign the scroll event context to `document.body` instead of `window`?

Discovery As I delved into the intricacies of web development, I stumbled upon a curious observation. In a particular MDN page, I noticed that the left and right sidebars had their scrollbars contained within themselves. However, the content block's ...

Verify if the textbox is empty

Is there a way to verify that the input field with type "text" is not empty before moving to the next page? <input TYPE="text" name="textbox2" align="center"> ........ function HomeButton() { <!--if both textbox1 and textbox2 values are not ...

The animation feature in Angular JS seems to be malfunctioning

Currently in the process of creating a slideshow using AngularJS, similar to the one found at this link, which includes navigation arrows (next and prev). Here is the HTML code snippet: <div class="carousel"> <div class="left"><input ty ...

Showing a PDF file within a Bootstrap modal

I'm encountering difficulties with a simple task. My goal is to display a PDF using the HTML <object> tag within a Bootstrap modal. I've put together a Plunkr to illustrate the issue. Essentially, there is a straightforward <object> ...

Obtaining the chosen value from a bootstrap dropdown button

Recently diving into Laravel and Bootstrap, I am faced with the task of extracting the selected value from a Bootstrap dropdown button and storing it in my database. Below is the code snippet for the dropdown list button: <div class="dropdown col-m ...

Eliminating the 'white-space' surrounding concealed images

I am currently working on a project where I have a list of images that need to be hidden or shown based on the click event of specific <li> elements. While I have managed to achieve this functionality successfully, I am facing an issue with white spa ...

The upper spacing is malfunctioning

Why is my margin-top not working when margin-left is functioning as expected? p.ex1 { margin-top: 15px; margin-left: 35px; } <div class="footer2"> <p class="ex1"> ABOUT US </p> <hr> <div class="footer"> &l ...

Utilizing Bootstrap Columns for Image Alignment: Struggling to Position an Image in the Center

For my latest project, I used Bootstrap to create a template that adapts well to different device breakpoints. Everything is working smoothly except for the positioning of the arrows on the sides of the image. I want them to be centered halfway down the ...

Retrieving checkbox values from a MySQL database in HTML/PHP

My database contains data stored in varchar format, such as S,M,L,XL. On my PHP page, I have checkboxes corresponding to these options. Is it feasible to fetch this data from the database and display the pre-checked checkboxes in HTML using PHP? (For exa ...

Best placement for <img> tag in HTML for creating a background image using CSS (excluding CSS3)

I am currently working on a programming project called Broadway through Codeacademy. I have been given the task of adding a background image to the webpage. It seems like an easy task to accomplish. The simplest way to achieve this effect is by using the f ...

The functionality of the "#Next" and "#Prev" features in the Tiny carousel are currently not functioning properly within the MVC project

Looking to implement a simple content carousel using jQuery 2.1.3 in my project. Previously used a non-responsive jQuery content carousel and switched to find a responsive option:Tiny Carousel Added Tiny Carousel's .js and .css files to Bundles.confi ...

Tips for creating a responsive <tr> table with <td> cells

Struggling to create a scrolling table with CSS? When using overflow-y : auto, the <td> tag becomes overloaded in the <tr> element. Take a look at the example code below to see the HTML and CSS in action: HTML CODE : <table id="check" cla ...

Transitionend event fails to trigger when Chrome tab is not in focus

$("#element").addClass("myclass").on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function (e) { $("#element").addClass('text-success'); $("#element2").addClass('myclass2'); setTimeout(function () { ...

Using an external JavaScript script may encounter difficulties when loading pages with jQuery

Trying to utilize jQuery for loading html posts into the main html page and enabling external scripts to function on them. Utilizing a script (load.js) to load posts into the index.html page: $(document).ready(function () { $('#header').loa ...

The Ajax request encountered a syntax error due to an unexpected token '<'

I have searched the forum extensively for similar questions, but unfortunately haven't found a suitable answer for my specific problem. In my jQuery code, I am attempting to make an AJAX call using the following snippet: function submitForm(formData) ...