Rearrange elements with a custom breakpoint trigger

Having four items with varying sizes lined up in a row can present some challenges. While larger screens may display them perfectly, issues arise on large screens (1199.98px/bootstrap 'lg') that require re-ordering of the div items.

Specifically, the third div needs to be positioned at the end. To illustrate this, I have created a corresponding code pen.

<!-- https://codepen.io/ibrahim-kunushefci/pen/OKJWzq -->

.hotelPr,
.hotelPr2,
.hotelPr3 {
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    background: #3161a3;
    border: 2px solid black;
}

.custom {
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    background: #bbbbbb;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div class="row">
    <div class="col-xl-2 col-lg-4">
        <div class="hotelPr">
            <p>Hotel</p>
        </div>
    </div>

    <div class="col-xl-2 col-lg-4">
        <div class="hotelPr2">
            <p>Hotel</p>
        </div>
    </div>

    <div class="col-xl-5 col-lg-10">
        <div class="custom">
            <p>This needs to be the last on small, medium, and large screens. But not in extra large</p>
        </div>
    </div>

    <div class="col-xl-3 col-lg-4">
        <div class="hotelPr3">
            <p>Hotel</p>
        </div>
    </div>
</div>

Answer №1

Include the class d-flex in your row container:

Also, add order-1 order-xl-0 to the column that requires re-ordering.

Answer №2

When working with flexbox, you have the ability to control the order in which sibling elements are displayed within a parent container.

I made some adjustments to the display properties of your .row div by implementing flexbox, and I included an order property for your col-xl-5 div.

.row{
  display: flex;
}

.hotelPr,
.hotelPr2,
.hotelPr3 {
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    background: #3161a3;
    border: 2px solid black;
}

.custom {
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    background: #bbbbbb;
}

.col-xl-5{
  order: 1; /* here */
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div class="row">
    <div class="col-xl-2 col-lg-4">
        <div class="hotelPr">
            <p>Hotel</p>
        </div>
    </div>

    <div class="col-xl-2 col-lg-4">
        <div class="hotelPr2">
            <p>Hotel</p>
        </div>
    </div>

    <div class="col-xl-5 col-lg-10">
        <div class="custom">
            <p>This needs to be the last on small, medium and large screens. But not in extra large</p>
        </div>
    </div>

    <div class="col-xl-3 col-lg-4">
        <div class="hotelPr3">
            <p>Hotel</p>
        </div>
    </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

Is there a way to ensure that a child mimics the behavior of its parent when adjusting the opacity and visibility properties of both elements?

Apologies for the ambiguous title, as I am struggling to accurately convey the issue I am encountering. To clarify the problem, I have created a jsFiddle. In my current layout, all four divs have opacity: 1 and visibility: visible, while divs a and b both ...

Having an issue with the 'scroll' event not being disabled in jQuery

Currently, we are encountering an issue with the implementation of a simple hiding menu when scrolling and showing it back once the user stops scrolling. The method .on('scroll') works as expected, but .off('scroll') is not functioning ...

Using jQuery to submit data via POST method without having the page reload

I have a link in the footer that, when clicked, jumps to the header with a # in the address bar. Is there a way to prevent this and stay in the footer? Here is the code snippet: <a href="#" class="clickIn" id="1" attrIn="Like"><span style="color ...

What causes offsetHeight to be less than clientHeight?

INFORMATION: clientHeight: Retrieves the height of an element, taking into account padding offsetHeight: Obtains the height of an element, considering padding, border, and scrollbar Analyzing the Data: The value returned by offsetHeight is expected to ...

What is the best way to achieve consistent alignment in Javascript?

I have been attempting to incorporate HTML code within JavaScript for alignment and styling. Despite searching on Google for 3 to 4 days, I have not found a suitable answer yet. What exactly am I looking for? Here is a snippet of my JavaScript code: funct ...

Tips on positioning the down arrow of an accordion-button to the left

I need to adjust the placement of the down arrow on an accordion button for my Arabic language website. Here is the current code snippet: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-c ...

What is the process for extracting HTML tables from files using pandas?

I am a beginner at pandas and I am attempting to extract data from HTML files. How can I convert multiple HTML tables like the ones below: PS4 Game Name | Price GoW | 49.99 FF VII R | 59.99 XBX Game Name | Price Gears 5 | 49.99 For ...

Expanding the width of CSS dropdown menus according to their content

When attempting to create a dynamic dropdown menu, I encountered an issue where the values were skewed in Internet Explorer if they exceeded the width of the dropdown. To fix this problem, I added select:hover{width:auto;position:absolute}. However, now th ...

Faulty toggle functionality within a JavaScript-created accordion panel

HTML I'm looking to add a FAQ question within the div with the class "section-center" <body> <section class="questions"> <div class="title"> <h2>FAQ SECTION</h2> < ...

Which html parsing tool is capable of processing encoding?

The journey begins -- I have a file saved on my computer that is an HTML page. When I view it in a regular web browser, the correct characters are displayed regardless of the encoding used. Then comes the challenge -- my task is to load the same file, par ...

Which DocType is most suitable for my web application?

I'm grappling with the HTML and XHTML specifications, and I can't decide which one to go for. Can you help me understand which is better? For instance, if I have a web application in PHP that searches an image database and displays results dynam ...

Issue with setting active class on current html page using Bootstrap 5 and Flask

I am currently developing a flask web application and I am focusing on customizing the navigation bar. Utilizing bootstrap 5 for styling purposes, I am attempting to apply the 'active' class when a specific navbar page is clicked with the followi ...

Expand the div width to the specified measurement horizontally

Is there a way to horizontally collapse a div (container) to a specific width that I can adjust, effectively hiding its content? The collapse effect should move towards the left. <div id="container"> <button type="button" id="myButton"> ...

What causes the offsetWidth attribute to be zero in an array of elements within the DOM?

I am encountering an issue with a script that sets widths for certain elements in the Dom. Specifically, when I use the code var elements = document.querySelectorAll("p.caption"), the first 12 elements display the correct offsetWidth, but the remaining hal ...

Steps to animate a div expanding to fit its content dimensions

I'm looking for a way to animate the opening of a div so that it adjusts to the size of its content. The content is fetched from a separate search using .load, which means it could be just a single line (no result) or multiple results that vary in hei ...

Desktop display issue: Fontawesome icon not appearing

Having trouble getting the fontawesome icon to display properly on my website. It appears in inspect mode, but not on the actual site itself. Any suggestions on how to fix this issue? import React, { Fragment, useState} from "react"; import { Na ...

Disabling an HTML attribute on a button prevents the ability to click on it

In my React application, I have a button component that looks like this: <button onClick={() =>alert('hi')} disabled={true}>test</button> When I removed the disabled attribute from the browser like so: <button disabled>test& ...

Is there a way to show new chat messages instantly without needing to refresh the entire page?

Creating a real-time chat application presents the challenge of displaying new messages instantly without requiring a page reload. Exploring different methods like reloading only the chat message container or treating new messages as individual chatMessage ...

Utilize jQuery to apply a border and background color to a table row when hovering over it

Is there a way to change the border of a table row along with its background color when the mouse hovers over it? Currently, I can only modify the background color using the following code: $(document).ready(function() { $(function() { $(&apos ...

There seems to be an issue with the functionality of the dropdown option in my HTML when integrated with my PHP code. I have implemented POST as the retrieval method, but unfortunately, it is resulting in

Is the POST method not appropriate for gathering information about the Employees? I previously used this form with just name, email, and phone fields, and it worked fine. As a PHP beginner, I'm feeling a bit overwhelmed. I trimmed down the form to av ...