Adaptable bootstrap grids and sections

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb9994948f888f899a8bbbced5c9d5c8">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <!-- Column 1 -->
    <div class="col-md-3">
      <p>Title1:</p>
      <p>Title2:</p>
      <p>Title3:</p>
    </div>

    <!-- Column 2 -->
    <div class="col-md-3">
      <p>Value1</p>
      <p>Value2 Value2 Value2 Value2 Value2 Value2Value2 Value2 Value2</p>
      <p>Value3</p>
    </div>

    <!-- Column 3 -->
    <div class="col-md-3">
      <p>Title4</p>
      <p>Title5</p>
      <p>Title6</p>
      <p>Title7</p>
       <p>Title8</p>
    </div>

    <!-- Column 4 -->
    <div class="col-md-3">
      <p>Value4</p>
      <p>Value5</p>
      <p>Value6</p>
      <p>Value7</p>
      <p>Value8</p>
    </div>
  </div>
</div>

The bootstrap layout provided above has the following structure and functionality:

Column 1 contains the title for the values displayed in column 2, while column 3 holds the titles for the values in column 4.

The issue arises when the content in column 2 is too large, causing it to span multiple rows. In such cases, the title in column 1 remains static, leading to an inconsistent display of data. To address this, the title in column 3 should align with the end of the content in column 2.

How can this alignment be achieved to ensure a visually cohesive display?

Answer №1

Breaking down the table into individual rows solves the issue and maintains consistent row heights. Give this a try!

<div class="container">
  <div class="row">
    <p class="col-md-3">Title1:</p>
    <p class="col-md-3">Value1</p>
    <p class="col-md-3">Title5</p>
    <p class="col-md-3">Value5</p>
  </div>
  <div class="row">
    <p class="col-md-3">Title2:</p>
    <p class="col-md-3">Value2 Value2 Value2 Value2 Value2 Value2 Value2 Value2</p>
    <p class="col-md-3">Title6</p>
    <p class="col-md-3">Value6</p>
  </div>
  <div class="row">
    <p class="col-md-3">Title3:</p>
    <p class="col-md-3">Value3</p>
    <p class="col-md-3">Title7</p>
    <p class="col-md-3">Value7</p>
  </div>
  <div class="row">
    <p class="col-md-3">Title4:</p>
    <p class="col-md-3">Value4</p>
    <p class="col-md-3">Title8</p>
    <p class="col-md-3">Value8</p>
  </div>
</div>

Alternatively, to maintain the same HTML structure, you can utilize JavaScript to determine the height of each <p> element and assign them a class based on their corresponding row. Then set the height of all elements in a row to match the element with the maximum height. Here's how:

<!-- Add class="row#" to each <p> element to connect them to a JavaScript constant -->

<div class="container">
    <div class="row">
      <!-- Column 1 -->
      <div class="col-md-3">
        <p class="row1">Title1:</p>
        <p class="row2">Title2:</p>
        <p class="row3">Title3:</p>
      </div>
      <!-- Column 2 -->
      <div class="col-md-3">
        <p class="row1">Value1</p>
        <p class="row2">Value2 Value2 Value2 Value2 Value2 Value2Value2 Value2 Value2</p>
        <p class="row3">Value3</p>
      </div>
      <!-- Column 3 -->
      <div class="col-md-3">
        <p class="row1">Title4</p>
        <p class="row2">Title5</p>
        <p class="row3">Title6</p>
        <p class="row4">Title7</p>
        <p class="row5">Title8</p>
      </div>
      <!-- Column 4 -->
      <div class="col-md-3">
        <p class="row1">Value4</p>
        <p class="row2">Value5</p>
        <p class="row3">Value6</p>
        <p class="row4">Value7</p>
        <p class="row5">Value8</p>
      </div>
    </div>
  </div>

<script>
    const rowElements = [
    document.querySelectorAll(".row1"),
    document.querySelectorAll(".row2"),
    document.querySelectorAll(".row3"),
    document.querySelectorAll(".row4"),
    document.querySelectorAll(".row5")
  ];
  
  rowElements.forEach(row => {
    let maxHeight = 0;
    row.forEach(rowElement => {
      const rowHeight = rowElement.offsetHeight;
      maxHeight = Math.max(maxHeight, rowHeight);
    });
  
    row.forEach(rowElement => {
      rowElement.style.height = `${maxHeight}px`;
    });
  });
</script>

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

Does the DOMContentLoaded event fire only after all script tags have been downloaded?

Imagine this situation: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>Document</title> </head> <body> <script src="js/heavy_js_file.js" defer></script> &l ...

I want to have a video playing in the background of my home page, but when viewers access it on their mobile devices, I would like to display a specific image instead

Is there a specific attribute I can include to make the image display instead of the video on mobile or small devices? ...

Guide to linking properties to Bootstrap 5 components within Angular

I am currently using Angular 13 along with Bootstrap 5. The bootstrap elements are functioning perfectly fine for static content. <button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" title="Popo ...

Transforming a Multi-Dimensional Array into an HTML Table

Experimenting with a new idea. I hope the solution is straightforward; I just can't seem to figure it out. Imagine I have an array like this: var items = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]; My goal is to rearrange the data so that it looks like t ...

Display the scroll bar in HTML only when the content exceeds the maximum height

I am trying to display a scrollbar only if the content is larger than the specified max-height. However, it seems that the scrollbar is always enabled. <div style="text-align: left; font-size: 1.5rem; max-height: 7rem; overflow-y: auto;"& ...

Why isn't my HTML reflecting the CSS changes I've made?

My CSS code is not applying to the HTML in general, only to h1 and h3. I have used similar looking code before and it worked fine. html { text-align:center; border:25px dotted #ff5c33; background-color:#00b300; color:#ff5c33; font-fami ...

Steps for displaying innerHTML values conditionally with a pipe

Currently working with Angular 8 and looking to conditionally implement the innerHTML feature using a translation pipe. .html <button type="button" mat-flat-button // utilizing translate module internally [innerHTML] = "display ? (HIDE ...

List formatted in a table

Can a list be inserted into a table using markdown? I attempted to research this but came up empty-handed. An example of a Table: Fruit |Color ---------|---------- Apples |Red Pears |Green and an example of a list: List item 1 List item 2 ...

Fieldset containing a table with a horizontal scrollbar

One issue I encountered in my application was dealing with a fieldset that contained table data with potentially many columns. To prevent the browser window from acquiring a horizontal scroll bar due to the wide table, I attempted to wrap the table in a c ...

What is causing the variables in my HTML tags to not appear?

I am currently working on a component to display random products from an array. Despite being able to see the attributes like props.products[random].company when I console log them, they are not rendering properly when placed inside HTML tags. Although th ...

Tips for adjusting image hues in Internet Explorer?

I have successfully altered the colors of PNG images in Chrome and Firefox using CSS3. Here is my code: #second_image{ -webkit-filter: hue-rotate(59deg); filter: hue-rotate(59deg); } <img src='http://i.im ...

Missing td data when using Beautiful Soup to parse HTML tables in Python

When attempting to extract a table using Beautiful Soup, I encounter an issue. from selenium import webdriver from bs4 import BeautifulSoup import pandas as pd import numpy as np import lxml import xlrd HorseNo = ["T421"] ...

What is the rationale behind positioning the closing right angle-bracket of an HTML tag next to the opening left angle-bracket of a different HTML tag?

I came across a clever trick using this coding structure where the ending tag 'angle bracket' is placed at the beginning of a new left 'angle-bracket' tag opening. Unfortunately, I can't recall why it was done or where I saw it. I ...

Insert between the top navigation bar and the sidebar menu

I am currently in the process of designing my very first website and I have encountered a bit of trouble. I would like to add a page between a navbar and a vertical bar, and I want this page to be displayed when a button on the vertical bar is clicked. You ...

Creating a seamless scrolling experience with a designated stopping point - here's how to achieve it!

I understand how to implement a scroll effect on an element with a specific class or ID. However, I am unsure of how to make the scrolling stop 20px above that element. I have seen examples using document.getElementById() to achieve this: function scr ...

Is there a way to create a dropdown selection for font families with vue js?

Here is a select element with font families that I want to apply to my texts: <select v-model="focused_font"> <option value="" disabled selected>Font</option> <option v-for="font in available_fonts" ...

Using CSS3 easing on Mobile Safari can help create smooth transitions

Can anyone advise on how to recreate the easing/friction for touch events in Mobile Safari? I am trying to achieve a similar bounce-back effect when dragging contents past the top or bottom of a scroller. I experimented with the cubic-bezier easing functi ...

Struggling to locate the element using xpath on a JavaScript enabled website in Selenium with Chrome

I have been attempting to extract data from a website that utilizes Javascript. Despite researching similar inquiries on xpath in Selenium, I have not found a solution. I initially tried using requests, but as the JavaScript doesn't load completely, I ...

Looking to retrieve the values of a 3-level dropdown using ajax. Successfully fetched the value of the 1st dropdown, but unsure of how to retrieve the values of the 2nd and

I have successfully managed to retrieve all values, but when the 2nd and 3rd drop-downs are populated through Ajax, how can I access those values? I am looking for a way to fetch the values of the 2nd and 3rd drop-down without resorting to session variable ...

Top tips for optimizing HTML and utilizing div elements

Could you please provide some insights on how to effectively utilize HTML5 in conjunction with div tags? Below is the snippet of my HTML code. I am incorporating the article tag and have segmented sections, which seem to be in order. However, I am also ...