Creating a dynamic Bootstrap design featuring variable height column content within a row, properly adjusting and wrapping them on various screen sizes

https://i.sstatic.net/eFfgY.png Looking for a way to properly position blocks using bootstrap4 based on screen size. When the screen is larger, all blocks should be in a row. However, when the screen size is reduced to medium, the rightmost block should move below the first one. I have tried using the d-none class and it works but it requires repeating the code. Is there a better way to achieve this layout? Thank you!

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row no-gutters">
  <div class="col-sm-12 col-md-6 col-lg-4" style="background-color: red; height: 60px">
    <p>Bread Crump</p>
    <p>Bread Crump</p>
<div class="d-none d-md-block d-lg-none mt-2" style="background-color: pink; height: 100px">
<p>List</p>
<p>List</p>
<p>List</p>
    </div>
  </div>
  <div class="col-sm-12 col-md-6 col-lg-4" style="background-color: green; height: 150px">
    <p>Name</p>
    <p>Name</p>
    <p>Name</p>
    <p>Name</p>
  </div>
  <div class="col-sm-12 col-md-6 col-lg-4 d-md-none d-lg-block" style="background-color: pink; height: 100px">
    <p>List</p>
    <p>List</p>
    <p>List</p>
  </div>
</div>

Answer №1

If you're working with Bootstrap 4, the best way to re-order columns at different breakpoints is by utilizing the order classes. Here's an example of how it can be done:

<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 no-gutters">
    <div class="col-sm-12 col-md-6 col-lg-4" style="background-color: red;">
        <p>Bread Crump</p>
        <p>Bread Crump</p>
    </div>
    <div class="col-sm-12 col-md-6 col-lg-4" style="background-color: green; height: 150px">
        <p>Name</p>
        <p>Name</p>
        <p>Name</p>
        <p>Name</p>
    </div>
    <div class="col-sm-12 col-md-6 col-lg-4 order-md-2 order-lg-3" style="background-color: pink; height: 100px">
        <p>List</p>
        <p>List</p>
        <p>List</p>
    </div>
</div>

The order-md-2 class assigns place 2 on medium (md) screens and above for a specified column.

The order-lg-3 class assigns place 3 on large (lg) screens and above for a specified column.

To simplify the code and use just one order class, consider rearranging the HTML like this:

<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 no-gutters">
    <div class="col-sm-12 col-md-6 col-lg-4" style="background-color: red;">
        <p>Bread Crump</p>
        <p>Bread Crump</p>
    </div>
    <div class="col-sm-12 col-md-6 col-lg-4 order-md-3" style="background-color: pink; height: 100px">
        <p>List</p>
        <p>List</p>
        <p>List</p>
    </div>
    <div class="col-sm-12 col-md-6 col-lg-4" style="background-color: green; height: 150px">
        <p>Name</p>
        <p>Name</p>
        <p>Name</p>
        <p>Name</p>
    </div>
</div>

In the second code snippet, using the order-md-3 class tells the second column:

"You are normally second here but from the medium breakpoints onwards, you will be third!"

It's worth noting that you could apply the same approach to the second column in the first code snippet as well (using the order-md-3 class), showcasing different options.

Additionally, consider employing the order-md-last class on the second column to instruct it to assume the last position from the medium breakpoint onwards.

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

Dynamic header that adjusts to fit window size fluctuations

I'm currently working on a website and trying to make it responsive by adjusting to changes in the browser window size. I'm having trouble changing the header height based on the window size unlike how it works for my pictures in CSS: #l ...

Styling Drawn Elements on a Canvas Using CSS

Can CSS Animations be applied to a circle drawn on a canvas using JavaScript? Specifically, I am using an AngularJS directive for this purpose: https://github.com/angular-directives/angular-round-progress-directive/blob/master/angular-round-progress-direct ...

Dynamic and static webpage

Is it possible to design a webpage using purely valid HTML and CSS that can dynamically adjust its size based on the browser window, while ensuring none of the content is lost or cut off? Please refer to the linked image for a visual representation of what ...

Check out this stylish Twitter-inspired SVG text counter created with a combination of CSS and jQuery! See it in action here: https://jsfiddle.net/moss24

Looking to develop a text counter similar to Twitter that increases the width in green color up to 75%, then switches to yellow until 98%, and finally turns red if the input value is greater than or equal to 400. It should also add a "highlight" class when ...

Can you specify the doctype used for XHTML5, which is the XML representation of HTML5?

Which doctype is recommended for XML serialization of HTML5? If I keep the file extension as .html, can I still indicate to the browser that the content is XHTML5? ...

Move buttons from one group to another group

I have a task to update a group of buttons with different buttons depending on the initial button chosen. Button1: when clicked, both buttons will be replaced by Button1a and Button1b Button2: when clicked, both buttons will be replaced by Button2a ...

Adjust the color of the whole row in an HTML table by changing the background

I am struggling with styling my dynamic table that pulls data from an API. I have successfully generated the table and inserted rows using JavaScript. However, I am facing styling issues. The colors of my table rows are inconsistent (similar to when using ...

Revamping the design of a menu bar in WordPress

I designed a navigation bar and now I'm looking to customize the CSS for it in WordPress. Specifically, I want to be able to reference the nav bars by name from PHP to CSS. It seems like there are just two dots representing variables. Here is the co ...

Showing different HTML elements based on the link that is clicked

Recently, I delved into the world of web development and decided to test my skills by creating a basic webpage with an interactive top navigation bar. Depending on the link clicked, specific HTML elements would be displayed while turning off others using a ...

Eliminating unnecessary gaps caused by CSS float properties

I need help figuring out how to eliminate the extra space above 'Smart Filter' in the div id='container_sidebar'. You can view an example of this issue on fiddle http://jsfiddle.net/XHPtc/ It seems that if I remove the float: right pro ...

How can one get rid of a sudden strong beginning?

Recently, I delved into the world of CSS animation and encountered a frustrating issue. I've tried numerous methods and workarounds to achieve a smoothly looping animation without interruptions. Despite my efforts, I have not been able to replicate th ...

Using Python API to directly upload web files to Drive via URL

Currently working with the Drive REST v3 Python client library. I have successfully managed to upload files from my local machine to Google Drive. However, I am struggling to figure out how to upload files directly from the web to Google Drive using downlo ...

Implementing JavaScript functionality upon page load with ASP.NET

I have come across a situation where I am trying to integrate working code (jQuery/Javascript) that makes an API call and sends data to it. The API service then responds with a success or failure message based on the data insertion into the API db. Everyth ...

Having trouble deleting element despite having the correct ID?

Whenever I click on the map, it adds an element to the map div using this line of code: $('#map').append('<label>test:</label><input type="hidden" name="map_coords" id="' + e.latlng.lat + '" value="' + e.latlng ...

Issues with CSS not being applied when the page content exceeds the viewport

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Unique Title</title> <style> #div1 { posit ...

javascript doesn't execute the php script

Hello everyone, I've been working on a project for quite some time and I’ve encountered an issue that I can't seem to solve. Hopefully, you can help me out with this. I have a digital LED strip controlled by an Arduino, which in turn is control ...

A dynamic jQuery plugin that replicates the smooth page sliding animation found in iPhone apps

Currently, I am in search of a jQuery plugin that has the capability to navigate users to different pages on a website with a sleek sliding animation, similar to what we see in some widely used iPhone apps. Despite my best efforts to create this functional ...

Encountering an error: [nsIWebProgressListener::onStatusChange] when utilizing jQuery AJAX within a click event?

Greetings! I am currently learning how to implement AJAX with jQuery to load an HTML document into a div element within another HTML document. Here is the approach I am using: function pageload() { $.ajax({ url: 'Marker.aspx', ...

An anchor-shaped name tag with a touch of flair

I stumbled upon this unique anchor name design on the website Does anyone here know how to create something similar? What is that style called? ...

Individuals have the capability to utilize .php as an image extension

It seems that someone is able to use any type of extension as long as they add .png at the end of the link. is currently being used, causing users on my website to log out when visiting the homepage. I tried to stop this issue, but unfortunately, my sol ...