Creating equal height nested rows in Bootstrap 4

For this particular requirement, the goal is to create a simple landing page with two main topics, each having a subtopic. The layout should adjust based on the device it's being viewed on - one column for mobile and side-by-side for desktop. Additionally, the alignment of topics and subtopics needs to change accordingly.

<div class="container-fluid">

<!-- Subtitles are on the same height but the order on mobile is wrong -->
    <div class="row">
        <div class="col-md-6">
            <h1>Topic 1</h1>
            <p>Four lines of text<br>Line2<br>Line3<br>Line4</p>
        </div>
        <div class="col-md-6">
            <h1>Topic 2</h1>
            <p>Two lines of text<br>Line2</p>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <h2>Subtopic 1</h2>
            <p>Number of lines<br>do not matter</p>
        </div>
        <div class="col-md-6">
            <h2>Subtopic 2</h2>
            <p>But Subtopic 1 and Subtopic 2 should be<br>vertically aligned while >=md<br>and when <md, Subtopic 1 shold be below Topic 1, not below Topic 2</p>
        </div>
    </div>

<hr>

<!-- Display on mobile is correct but subtitles on desktop are not aligned anymore -->
    <div class="row">
        <div class="col-md-6">
            <h1>Topic 1</h1>
            <p>Four lines of text<br>Line2<br>Line3<br>Line4</p>
            <div class="row">
                <div class="col">
                    <h2>Subtopic 1</h2>
                    <p>Number of lines<br>do not matter</p>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <h1>Topic 2</h1>
            <p>Two lines of text<br>Line2</p>
            <div class="row">
                <div class="col">
                    <h2>Subtopic 2</h2>
                    <p>But Subtopic 1 and Subtopic 2 should be<br>vertically aligned while >=sm<br>and when <sm, Subtopic 1 shold be below Topic 1, not below Topic 2</p>
                </div>
            </div>
        </div>
    </div>

</div>

Facing some challenges in addressing these design requirements effectively. Any tips or suggestions would be greatly helpful.

Answer №1

To achieve this layout, you can utilize the order utility classes provided by Bootstrap. Simply adjust your markup so that all elements are on the same level:

<div class="container-fluid">
    <div class="row">
        <div class="order-0 order-md-0 col-md-6">
            <h1>Topic 1</h1>
            <p>Four lines of text<br>Line2<br>Line3<br>Line4</p>
        </div>
        <div class="order-2 order-md-1 col-md-6">
            <h1>Topic 2</h1>
            <p>Two lines of text<br>Line2</p>
        </div>
        <div class="order-1 order-md-2 col-md-6">
            <h2>Subtopic 1</h2>
            <p>Number of lines<br>do not matter</p>
        </div>
        <div class="order-3 order-md-3 col-md-6">
            <h2>Subtopic 2</h2>
            <p>But Subtopic 1 and Subtopic 2 should be<br>vertically aligned while &gt;=md<br>and when &lt;md, Subtopic 1
                    shold be below Topic 1, not below Topic 2</p> </div> </div> <hr>
        </div>
    </div>
</div>

For more information, refer to the documentation here.

Alternatively, you can either set a fixed height for your topic columns or dynamically adjust their heights using JavaScript based on the tallest column.

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

Utilize JavaScript to enclose every piece of text within single quotes in a span element

I have a tiny snippet of text: "some sample text" just a little more "additional text" I am trying to figure out how to wrap all the content between quotation marks in a span container, similar to what hilight.js does. I've been struggling to make it ...

What is the distance between the different segments in HTML code?

I have the following HTML structure: <body cz-shortcut-listen="true"> <div id="panels"> <section id="sect0" name="lvl0"> <div id="divLvel0" class="level zero"> <h2>top<nav><ul& ...

The alignment of the label on the Watu Quiz does not match with the Radio Button

I've encountered an issue with a Watu quiz I created where the labels are not aligning with the radio buttons. Any suggestions on how to style this and fix the alignment? You can view the page here. Here is a screenshot for reference: https://i.sst ...

Chatbots access a MediaWiki page

Can a Chatbot in Facebook Messenger, Telegram, or Kik be designed to integrate a MediaWiki page? I have a MediaWiki page filled with business coaching materials. I am interested in developing a Chatbot that can access and showcase this content. Do any t ...

The design became distorted when the fonts were resized in every browser

Looking for assistance with a simple layout issue. When I scale the font in browsers by using CTRL and scrolling up (zooming), the layout does not behave as expected. I want #allWrapper to scale its dimensions with the body so that the white background ex ...

Exploring and deciphering the intricacies of the underlying technology

Apologies if this question seems misplaced, but as a complete beginner, I'm a bit lost. Let's consider this website as an example: I'm trying to uncover the libraries and technologies employed in the background to learn more and replicate ...

Selenium encountered difficulties retrieving every div element

My task was to extract all special div tags with a class name of "someClass" from a specific website The website required scrolling down to load new div elements. To achieve this, I used Keys.PAGE_DOWN which successfully scrolled the page, but the data wa ...

Automatically conceal a div or flash message after a short period of time by utilizing CSS3 in a React

I am relatively new to the React environment and recently created a basic component for a bookmarking feature. Essentially, when the favourite icon is clicked, an ajax call is sent > a record is created in the database > on ajax success, a flash me ...

Which is Better for Creating DropDown Menus: CSS or JavaScript?

Starting a new project that involves dropdown menus with categories and subcategories within them. I'm curious about the advantages of using CSS3 only menus compared to traditional JavaScript ones. There are several jQuery menu options available as we ...

The component is not responding to list scrolling

Issue with Scroll Functionality in Generic List Component On the main page: <ion-header> <app-generic-menu [leftMenu]="'left-menu'" [rightMenu]="'client-menu'" [isSelectionMode]="isSelectio ...

IE7 and IE6 Not Registering Required Field Indicator

Utilizing CakePHP's field validation and the typical CSS-based 'required field' indicator (red asterisk) functions smoothly across most browsers, with the exception of IE7 and IE6. It appears that these older versions of Internet Explorer a ...

Aligning images horizontally within individual div containers within a list

Struggling to align images horizontally, they are all stacked on top of each other. New to this and could use some assistance figuring it out! Any help would be appreciated! <div class="social"> <ul> <div class="facebook"> ...

Integrate a banner with a hyperlink to direct users to a different website

Looking to add a unique banner/icon to a webpage to show membership in our organization. Similar to icons seen at the bottom of certain websites like peer1 Hosting or cc-wiki. I have my own image and link, but need help with the code to implement it. Appr ...

Is it possible to modify this code to accept multiple IDs at once?

I'm attempting to create a form in JavaScript where, upon entering the necessary details and clicking submit, the user's email client opens with the information pre-filled for easy sending. However, I am facing challenges as my code involves mult ...

How to align text to the bottom of a div using CSS

I am struggling to position the text 'About' at the bottom of an image. The red line marks the spot where I want the text aligned at the bottom. However, every method I try results in inconsistent outcomes when viewed on desktop and mobile device ...

Top scroll button malfunctioning on this page

Updated question for better understanding. In my current project, let's imagine I am on the following URL: http://127.0.0.1:8000/blog/ and within that page I have the following HTML: <a href="#top">Back to top</a> Upon hovering over tha ...

What is the best method to align these images in the center of this div?

Struggling to center the images inside the div...any suggestions? I know it's basic, just getting back into it. Hopefully someone understands what I'm trying to achieve here? Tryin' to get those images centered in the div but can't fig ...

Exploring ways to retrieve checkbox values instead of boolean values upon submission in Angular

I am currently working with a template-driven form and facing an issue. Despite receiving true or false values, I actually need to retrieve the value of checkboxes. <form #f = "ngForm" (ngSubmit) = "onClickSubmit(f.value)"> ...

Updating React Component when state changes

I am currently facing an issue with my app where I have two functions, MyCart and MyItems. The goal is to trigger a method in the main app component (the parent) when the button rendered in MyItems is clicked, and update the state. However, the value in th ...

The battle of line-height versus padding for achieving vertical centering with one-lined text

One-lined text can be vertically centered using either the line-height property or by adding padding-top and padding-bottom. What are the advantages and disadvantages of each method? body { font-size: 12px; font-family: ...