Adjust the height of the rows in the column to match the height of the parent

I'm struggling to figure out how to make the child content fill the height of a column. I've tried using Bootstrap grid system and flex utilities.

The only solution that somewhat worked was setting the row height to 50%, but the issue is, I don't know how many rows will be in a column (could be 1, 2, or 3 rows):

This is my desired layout:

<html>
    <head>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a2825253e393e382b3a0a7e647c6478">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
        <style>
            .c1{
                background-color: red;
            }
            .c2{
                background-color: rgb(98, 0, 255);
            }
            .c3{
                background-color: rgb(101, 255, 160);
            }
            .c4{
                background-color: rgb(72, 255, 0);
            }
            .c5{
                background-color: rgb(0, 255, 242);
            }
            .c6{
                background-color: rgb(255, 238, 0);
            }
            .r0{
                background-color: rgb(133, 133, 133);
            }
            .ra{
                background-color: rgb(255, 123, 0);
                height: 50%;
            }
            .rb{
                background-color: rgb(72, 255, 0);
                height: 50%;
            }
            .rc{
                background-color: rgb(255, 0, 191);
            }
            .rd{
                background-color: rgb(240, 255, 24);
            }
            .re{
                background-color: rgb(111, 133, 255);
            }
            .rf{
                background-color: rgb(180, 57, 57);
                height: 50%;
            }
            .rg{
                background-color: rgb(91, 206, 110);
                height: 50%;
            }
        </style>
    </head>
    <body>
        <div class="container py-3">
        <div class="row r0">
            <div class="col c1">
                <div class="row ra">a</div>
                <div class="row rb">b</div>
            </div>
            <div class="col c2">2</div>
            <div class="col c3">3</div>
            <div class="col c4">
                <div class="row rc">c</div>
                <div class="row rd">d</div>
                <div class="row re">e</div>
            </div>
            <div class="col c5">
                <div class="row rf">f</div>
                <div class="row rg">g</div>
            </div>
        </div>
        </div>
    </body>
</html>

Here's what I attempted:

<html>
    <head>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f6fbfbe0e7e0e6f5e4d4a0baa2baa6">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
        <style>
            .c1{
                background-color: red;
            }
            .c2{
                background-color: rgb(98, 0, 255);
            }
            .c3{
                background-color: rgb(101, 255, 160);
            }
            .c4{
                background-color: rgb(72, 255, 0);
            }
            .c5{
                background-color: rgb(0, 255, 242);
            }
            .c6{
                background-color: rgb(255, 238, 0);
            }
            .r0{
                background-color: rgb(133, 133, 133);
            }
            .ra{
                background-color: rgb(255, 123, 0);
            }
            .rb{
                background-color: rgb(72, 255, 0);
            }
            .rc{
                background-color: rgb(255, 0, 191);
            }
            .rd{
                background-color: rgb(240, 255, 24);
            }
            .re{
                background-color: rgb(111, 133, 255);
            }
            .rf{
                background-color: rgb(180, 57, 57);
            }
            .rg{
                background-color: rgb(91, 206, 110);
            }
        </style>
    </head>
    <body>
        <div class="container py-3">
        <div class="row r0">
            <div class="col c1">
                <div class="row ra">a</div>
                <div class="row rb">b</div>
            </div>
            <div class="col c2">2</div>
            <div class="col c3">3</div>
            <div class="col c4">
                <div class="row rc">c</div>
                <div class="row rd">d</div>
                <div class="row re">e</div>
            </div>
            <div class="col c5">
                <div class="row rf">f</div>
                <div class="row rg">g</div>
            </div>
        </div>
        </div>
    </body>
</html>

And here's the outcome

Answer №1

Avoid using bootstrap's grid system in this scenario as it does not align with the grid structure you are aiming for.

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The above code is for demonstration purposes only */

.my-container>.flex-column {
  width: 100px; /* Width of each column */
}

.my-container>.flex-column>div {
  flex: 1 1 0px;
}

.c1 {
  background-color: red;
}

.c2 {
  background-color: rgb(98, 0, 255);
}

.c3 {
  background-color: rgb(101, 255, 160);
}

.c4 {
  background-color: rgb(72, 255, 0);
}

.c5 {
  background-color: rgb(0, 255, 242);
}

.c6 {
  background-color: rgb(255, 238, 0);
}

.r0 {
  background-color: rgb(133, 133, 133);
}

.ra {
  background-color: rgb(255, 123, 0);
}

.rb {
  background-color: rgb(72, 255, 0);
}

.rc {
  background-color: rgb(255, 0, 191);
}

.rd {
  background-color: rgb(240, 255, 24);
}

.re {
  background-color: rgb(111, 133, 255);
}

.rf {
  background-color: rgb(180, 57, 57);
}

.rg {
  background-color: rgb(91, 206, 110);
}
<head>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="12707d7d66616660736252263c243c20">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>

<body>
  <div class="d-flex py-3 my-container">
    <div class="d-flex flex-column">
      <div class="ra">a</div>
      <div class="rb">b</div>
    </div>
    <div class="d-flex flex-column">
      <div class="c2">2</div>
    </div>
    <div class="d-flex flex-column">
      <div class="c3">3</div>
    </div>
    <div class="d-flex flex-column">
      <div class="rc">c</div>
      <div class="rd">d</div>
      <div class="re">e</div>
    </div>
    <div class="d-flex flex-column">
      <div class="rf">f</div>
      <div class="rg">g</div>
    </div>
  </div>
</body>

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

Create a rectangular container with text using CSS

Looking to achieve a square box design using CSS with specific dimensions? Want to insert text inside the square and ensure it is horizontally centered within the square? Check out this code snippet: #myid { width: 100px; height: 100px; ...

Partial success with jQuery dark mode toggle feature

Setting up a dark-mode toggle feature for a project, but encountering issues with switching back to light-mode after toggling Defined two classes to control the background and text color of the body element. Although toggling on darkmode works smoothly, ...

Dealing with unsupported CSS properties in Next.js or implementing @supports directives in Chakra-UI

Currently, I am working on a React component that adjusts opacity values based on the support for the CSS backdrop-filter directive: background={(() => { const opacity = isBackdropFilterSupported() ? 0.75 : 0.98 return ( `linear-gradient( ...

What is the best way to retrieve AJAX post data from the request in Symfony2?

My goal is to efficiently upload a file using jquery-file-upload (blueimp) and include some data in a cross-domain environment. To achieve this, I have utilized code from the basic.html file provided by jqueryfileupload on the client side. Additionally, I ...

Middle position of the rotating display

Currently working on a shop's image carousel where I'm implementing scroll-snap-type: x mandatory; for the container and scroll-snap-align: center; for the images. However, running into a challenge where the container sometimes exceeds the width ...

using jquery, how can you send multiple parameters in an ajax request

Hello and welcome! I'm having trouble passing parameters through an ajax URL. I am attempting to send multiple data using the jQuery $.ajax method to my PHP script, but I can only pass a single data item when concatenating multiple data entries toget ...

Tips for transferring a JavaScript variable to a servlet

I have implemented the selectable jquery plugin on my JSP page. I need to pass the selected string as a parameter to a servlet when the form is submitted. $(function() { $("#selectable").selectable({ stop: function() { var result = ...

Having issues with the Carousel feature in Bootstrap 5.3.1 while using Angular version 15

I'm currently in the process of setting up a carousel on my homepage. It seems like everything is in place, but there's something missing. The initial image, text, and arrows all display properly, but they are non-functional. I have correctly imp ...

What is the best way to evenly distribute input elements horizontally within the parent container?

I am working on a layout with five select inputs that I want to arrange horizontally within the parent div. However, the current code setup is not achieving the desired layout: <div id="divtable"> <select class="abc"></select> ...

Angular: Generating components dynamically in HTML is unsuccessful

I possess the capability to dynamically generate components: import { Component, ComponentFactory, ComponentFactoryResolver, ComponentRef, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; import { FilterComponent } from '../filter ...

Toggle the visibility of multiple divs depending on a specific attribute value

I previously inquired about this issue, but I believe my wording was unclear and the responses focused on how to display or hide a group of divs when clicking a button. While I understand that concept, my specific challenge is slightly different. Let me pr ...

Providing the outcome in JSON format rather than HTML

Seeking assistance with calling and displaying a Java web service in ASP.NET Web API. How can I configure my ASP.NET Web API to display JSON data instead of HTML when run? Below are the relevant code snippets: DemoRestfulClient.cs public class DemoRestf ...

Is there a way to adjust the height of one div based on the height of another div in Bootstrap?

I am experimenting with a Bootstrap example featuring a table in the left column and 4 columns in 2 rows in the right column. Check out the code below: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css ...

Changing the class when a checkbox is selected using JQuery

I’m working on a bootstrap switcher and I want to change the panel color from grey to green when the checkbox (switch) is checked. I had it working before, but after updating the switcher, it no longer functions properly. Here is the main code for the s ...

What are the best methods for detecting devices in order to create customized CSS styles for iPad and Galaxy Tab?

Ensuring my web application is compatible with various devices is crucial. While I have created a common CSS for all mobile and tablet devices, it seems to be causing some problems specifically on the iPad. After finding a fix tailored for the iPad, I now ...

What is the best method to implement a loading spinner within a React and Node application while using Nodemailer?

Is it possible to implement a functionality where clicking the Send button triggers a spinner next to the button, followed by changing the button text to "Message Sent"? I managed to change the button text, but there is no loading time, it happens instantl ...

Attach data to a specific position within a jQuery DataTable

Hello everyone! I'm currently attempting to integrate tableInfo into a jquery DataTable, as shown below: However, when I modify the value in show-list, the information shifts down to the center of the column, as illustrated here: I have experimented ...

When utilizing drag and drop in HTML5, the items.webkitGetAsEntry() method is not available

Hey there, I am attempting to drag and drop files into my file system using Chrome, but I encountered the following error in the console: var dnd = new DnDFileController('body', function(files, e) { var items = e.dataTransfer.items; for ...

Tips for employing clamp CSS to modify font size while maintaining alignment within a paper-inspired CSS grid

Currently, I am working on creating a responsive text section with a grid-like horizontal line resembling paper, and the challenge lies in aligning the text properly within this grid. While I can achieve this when the font size remains constant, I am curi ...

Adjust the size of a map on an HTML page after it has

Currently, I am utilizing Angular 2 to create a simple webpage that includes a Google 'my map' displayed within a modal. <iframe id="map" class="center" src="https://www.google.com/maps/d/u/0/embed?mid=1uReFxtB4ZhFSwVtD8vQ7L3qKpetdMElh&ll ...