Struggling to adapt container rows into columns for optimal responsiveness

https://i.sstatic.net/uxGVK.png

My current project involves creating responsive HTML code for the image above. Below is the code I have developed so far to achieve the desired design:

HTML:

    <div class="container-fluid">
  <div
    class="row low-height box border bg-light justify-content-start align-content-start   overflow-box"
  >
    <div class="col-1 border bg-primary small-box m-2"></div>
    <div class="col-1 border bg-primary small-box m-2"></div>
  </div>
  <div
    class="row low-height box border bg-light justify-content-end align-content-end"
  >
    <div class="col-1 border small-box bg-success m-1"></div>
  </div>
  <div
    class="row low-height box border bg-light justify-content-center align-content-center"
  >
    <div class="col-lg-12 text-center"><h4>Title</h4></div>
  </div>
</div>

CSS:

.box {
   height: 200px;
  margin-bottom: 10px;
}
.small-box {
  height: 100px;
}

.overflow-box {
  overflow: auto;
}

Issue:

When the browser height is less than 600px, the 3 main sections should be arranged horizontally as depicted in the image below.

I have been unable to solve this part of the project and couldn't find relevant information on the bootstrap site. It's possible that I am overlooking a fundamental aspect. Any assistance would be greatly appreciated.

https://i.sstatic.net/X8IAs.png

Answer №1

You have the option to include a media query in your CSS stylesheet,

@media(max-height:600px) {
    //You can specify custom CSS for this particular condition
    //For example,
    [class*="col"]{
    width:33%!important;
  }
}

Here is a practical demonstration

@media(max-height:600px) {
  [class*="col"]{
    width:33%!important;
  }
}

.box {
  text-align:center;
  padding:5rem;
  background-color: #22ccff;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abc9c4c4dfd8dfd9cadbeb9e859a8598">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="781a17170c0b0c0a1908384d5649564b">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="container-fluid">
  <div class="px-lg-12 px-md-12 px-sm-12">
    <div class="row">
      <div class="col-xl-12 col-lg-12 col-md-12 mb-4">
        <div class="box">Box-1
        </div>
      </div>
      <div class="col-xl-12 col-lg-12 col-md-12 mb-4">
        <div class="box">Box-2
        </div>
      </div>
      <div class="col-xl-12 col-lg-12 col-md-12 mb-4">
        <div class="box">Box-3
        </div>
      </div>
    </div>
  </div>
</div>

Answer №2

Instead of having separate rows for each of the three grey boxes, they should be structured as columns within a responsive Bootstrap grid.

I have revised the code to place each of the grey boxes in a

<div class="col-4 col-sm-12" ...>
so that they display as 3 columns on XS screens and 1 column on larger screens as per your request. (Typically, responsive sites collapse to one column on small screens and expand to multiple columns on larger screens.)

.box {
  height: 200px;
  margin-bottom: 10px;
}

.small-box {
  height: 100px;
}

.overflow-box {
  overflow: auto;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea8885859e999e988b9aaadec4dcc4db">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">

<div class="container-fluid">
    <div class="row">
        <div class="col-4 col-sm-12 low-height box border bg-light justify-content-start align-content-start overflow-box">
            <div class="row">
                <div class="col-1 border bg-primary small-box m-2"></div>
                <div class="col-1 border bg-primary small-box m-2"></div>
            </div>
        </div>
        <div class="col-4 col-sm-12 low-height box border bg-light">
            <div class="row justify-content-end align-content-end">
                <div class="col-1 border small-box bg-success m-1"></div>
            </div>
        </div>
        <div class="col-4 col-sm-12 low-height box border bg-light justify-content-center align-content-center">
            <div class="row">
                <div class="col-lg-12 text-center">
                    <h4>Title</h4>
                </div>
            </div>
        </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

List of items:1. The first item is elevated in its position

Can anyone explain why the first li item is displaying higher than the rest when I assign an id or class to the div element? https://i.sstatic.net/9SMdT.png Take a look at the code snippet below: <div id="pickList"> <ul *ngFor="let channel ...

Creating HTML inputs dynamically using jQuery in an ASP.NET application

I have written this JavaScript code to dynamically generate and add HTML elements within my asp.net webform: var i = 0; function addFields() { i++; var quantity = '<td class="auto-style2"><input type="text" size="3" name= ...

Click the button to add content to the top section of the div using jQuery

Looking for some assistance with a web development issue I'm facing. Here's the scenario: I have two sections on my webpage - TOP and BOTTOM. In the bottom section, there are 3 list records each with a checkbox and button. What I need help with ...

Troubleshooting: Issues with Adding a New Row in Datatables using JQuery

CSS : <div class="datatable-header"> <button type="button" name="add" id="add" class="float-right btn btn-info">Add</button> </div> <div class="table-responsive"> <table ...

Tips for creating td/th elements with a consistent width?

I am currently working on a website where I need to create a table with fixed width td tags, rather than the entire table having a fixed width. This is necessary because I will be dynamically showing and hiding columns using jQuery, and also using a jQuery ...

Why won't the CSS style in my HTML file display properly in Django?

I've been encountering an issue with my CSS file not working in Django, and I'm unsure of the reason behind it. Despite numerous attempts to troubleshoot, the problem persists. I have included {%load static%} at the beginning of my HTML file, and ...

The popup generated by the window.open() function appears blank and does not display any content

I have a Django website with this url that contains the following code in its footer template: <img referrerpolicy='origin' id='rgvjjxlzwlaoesgtfukzjxlz' style='cursor:pointer' onclick='window.open("https://logo.sam ...

Importing CSS into the styles section of angular.json is no longer feasible with Angular 6

Currently in the process of migrating a project to Angular 6, I'm facing an issue with importing my CSS file within the styles section of angular.json: "styles": [ "./src/styles.css", "./node_modules/primeng/resources/primeng.min.css", ...

Exploring Concealed Data and Corresponding in jquery, javascript, and html

A unique template contains 2 hidden fields and 1 checkbox. Using the function addProductImage(), the template is rendered and added to the HTML page. To retrieve the values of the hidden fields (thisFile and mainImage) from a dynamically generated div wit ...

Position form elements flush with div containers

.quantity-button { height: 35px; width: 35px; padding-bottom: 1px; margin-bottom: 3px; font-weight: 600; font-family: Raleway; color: white; background-color: #AA95B9; border: 2px solid black; border-radius: 5px; cursor: pointer; display: -webkit-flex; dis ...

Encountering the error message "Cannot GET /" in a NodeJS Express

I've been experimenting with various approaches to resolve this issue, ranging from app.use(express.static(__dirname + "public")) to res.render. It seems to function correctly in my terminal environment but fails when I try to access it locally. Can a ...

I am having trouble accessing the database. Jacky @ localhost Password: NO

https://i.sstatic.net/7Kvfu.png What is preventing me from accessing the database? Username: jacky @ local host Password: NO ...

Sending a form using an AngularJS dropdown menu

I have recently started using angularjs and decided to switch out a traditional html <select> box for an angular modal select box. The select box successfully populates with data from a $http ajax request, but I am facing issues with form submission ...

The functionality to organize items appears to be malfunctioning. (Javascript)

I want to add a price sorting feature that allows users to sort by either 'high to low' or 'low to high' using a drop-down menu. The products I want to sort are the w3-containers, each representing a different product. However, nothin ...

Adjust the hue as you scroll

I've been searching for a solution to this issue, but I haven't been able to make it work. My goal is to have the page header change from a transparent background to a red background as the user starts scrolling down the page. $(window).on("s ...

Achieving distinct CSS margins for mobile and desktop devices in a Django template without the need for multiple {% block content %} statements

Is there a way to dynamically change the margin-left of my main {% block content %} in the base.html template based on whether the viewer is using a mobile or desktop device? This is how my current base.html looks like: <div class="content container-f ...

What are the steps to execute a file on localhost using an HTML page?

Currently, I have an HTML file that leverages the Google Calendar API javascript to read the next event on my calendar. The functionality works flawlessly when manually inserting a specific URL in a browser address window, which triggers a GET request in a ...

Is there a way to establish a universal font for all apps within ant design?

I am currently working with NextJS version 14 and I have the following setup: In my globals.css file, I have imported a Google font like so: @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@100;200;300;400;500;600;700;800& ...

Hide the div element once the timer runs out

Struggling to make a timer disappear when it reaches 00:00, every attempt results in the div being hidden immediately. Check out the code snippet I've been working with: $(document).ready(function(e) { var $worked = $("#worked"); function upd ...

IE compatibility problem with the alignment of input group buttons and textboxes in Bootstrap v4

Encountering an issue with input group in IE while using bootstrap v4, working fine in Chrome. Specifically using IE 11 Here is my plunkr: input group bootstrap v4 Chrome display: https://i.sstatic.net/yXtEW.png IE display: https://i.sstatic.net/WiRz ...