When viewing on smaller devices, columns in Bootstrap will have varying height ratios except for the 1:1 ratio

Initially, I was unsure about the kind of research I needed to conduct, which led me to asking a potentially duplicate question.

Nevertheless, the code I am working with is quite simple:

#my-container {
    height: 100vh;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />

<div id="my-container" class="container-fluid p-0 m-0">
    <div class="row p-0 m-0 h-100 text-white">
        <div class="col-sm-8 bg-success">COL 1</div>
        <div class="col-sm-4 bg-danger">COL 2</div>
    </div>
</div>

As depicted, I currently have two columns in an 8:4 ratio spanning the entire page. However, on smaller screens, they appear in two rows with a 1:1 ratio. Like this:

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

Yet, I am aiming for a different height ratio for these columns, such as an 8:2 ratio, as illustrated here: https://i.sstatic.net/R86gv.png

Answer №1

col-sm-8 and col-sm-4 determine the width of the columns, not their heights. To adjust the columns' heights in a specific ratio, you can explicitly define their heights using a CSS @media query like this:

#my-container {
    height: 100vh;
}

@media(max-width: 600px) {
    #my-container .col-sm-8 {
        height: 66.66%;
    }
    #my-container .col-sm-4 {
        height: 33.33%;
    }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />

<div id="my-container" class="container-fluid p-0 m-0">
    <div class="row p-0 m-0 h-100 text-white">
        <div class="col-sm-8 bg-success">COL 1</div>
        <div class="col-sm-4 bg-danger">COL 2</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

Expanding CSS transition for child elements as they increase in size

I am currently working with Vuetify and have encountered an issue with a v-list-item that contains a title and a subtitle. The problem is that the title is restricted to displaying only one line. If the title exceeds this limit, it gets cut off and shows " ...

Customize the background color of a popup modal except for one element

After much searching without finding a solution, I am reaching out here for help. Whenever I click on a Bootstrap modal, a popup appears with a background color and CSS applied. My issue is that I want to prevent the Bootstrap modal from applying the backg ...

When the text overflows the boundaries of a paragraph in CSS HTML

I am facing an issue with text overflowing in a paragraph <p style="width:200px;">Text goes here</p> As the text in the paragraph increases in width, it does not automatically wrap to a new line, causing it to overflow outside the paragraph ...

Creating a vertically scaling div with full height using Bootstrap 3

I am facing an issue with creating a full-height website using Twitter because the body min-height set to 100% seems to be causing problems. Here is my CSS code: html{ height:100%; } body{ min-height:100% } #main{ min-height:100%; } And here ...

Error: The function window.intlTelInput is not recognized within the ReactJS framework

I am currently learning ReactJS and encountering an issue when using jQuery with React JS for intlTelInput. I have installed npm jQuery and imported all the necessary code. Additionally, I have included all the required CSS and jQuery links in my index.htm ...

Save data in MySQL and present a flexible number of rows in an HTML table

Let me illustrate the issue at hand with a hypothetical scenario involving numbers, although this may not be based on real data: In my system, up to 2 teachers grade a student on their performance of tasks. Let's say the student has to complete 10 ta ...

Combining two PHP includes within a single HTML file

As I delve into web development, an interesting issue has arisen: I have a single HTML file with two PHP includes. Strangely, only the first include is working while the second one seems to halt the transfer of HTML code to the browser. There are no errors ...

Tips for hiding a bootstrap modal in Angular4 when it has no content

I am currently working on an Angular 4 e-commerce application. One of the requirements is to hide a bootstrap modal when there are no products in the cart. When a user selects some products, they are added to the mycart modal screen. The user also has the ...

Increasing Gap between Tabs in Primefaces AccordionPanel: A Guide

Is there a way to increase the spacing between the tabs of a Primefaces AccordionPanel component? ...

How can I use an HTML button to activate a function that inserts text into a read-only text-box?

Trying to write a simple piece of HTML code that finds the number greater than or equal to the first initial amount that wholly divides the second given amount. The code attempts to divide the numbers, and if it fails, increments the first number by 1 and ...

To make the Bootstrap 4 spinner/loader gracefully disappear when the browser window has finished loading, utilize the fadeOut() or hide() function

THE GOAL My objective is to display a spinner/loader while the browser window is loading, and then have it fade or hide once the page is fully loaded. EFFORTS MADE I've attempted to use a jQuery code recommended in a different question (How to show ...

Cause a JavaScript error to occur if geolocation services are disabled

I have an AngularJS project where I am utilizing the following code snippet to fetch a device's GPS coordinates: // when user clicks on geo button $scope.getGeoLocation = function() { var geocoder = new google.maps.Geocoder(); window.navigato ...

When the span element's height is set to 100%, it does not automatically match the height of its parent div

I have a scenario where I am working with two div elements and a span element in between. The parent div element does not have a defined height, it is calculated based on the content within the div. However, the span element's height is set to 100% ev ...

My attempts to use media queries are being ignored by Internet Explorer

While other browsers recognize and function properly, it seems like IE is not recognizing my media queries. Could there be something wrong with my code? I've created a similar design before without any issues, so why is this one causing problems? Her ...

Extract the entire div including all its elements and then transmit it using the PHP mail function

Currently, I am developing a feature that allows users to send an email. The email should include only one div from the page which contains elements added using the jQuery drag and clone function. I am unsure how to copy the entire div along with its child ...

In AngularJS, I've created a collection of checkboxes with a submit button ready to go

One of my goals is to make the cancel button available only when at least one job is selected. Below is my HTML View <table> <tr ng-repeat="x in jobs" ng-class-odd="'odd'" ng-class-even="'even'"> <td style="widt ...

Styling a disabled button in ASP.NET using CSS

I've encountered an issue with my asp.net button that is disabled based on specific c# code conditions. The button, known as btnPrevious, is assigned the css class below: .btnBlue{ background: rgb(40, 108, 244); /* Old browsers */ background:linear-g ...

space required on the upper side of the cell

I have formatted a text (including title and paragraph) in a cell using CSS styles to achieve the desired appearance. The only thing left is to create some space between the top of the Title and the content below it. I attempted to use the margin parameter ...

Determining outcomes of forms added in real-time

Need assistance with dynamically creating tickets, calculating prices, and displaying results when additional tickets are added. Currently facing an issue where price data is not being calculated when a new ticket is added. Any help would be greatly apprec ...

using jQuery to disable textarea input

I have this HTML code and I am using jQuery: <div><textarea style="height: 150px; width: 250px" name="myName" id="myId" class="text ui-widget-content ui-corner-all" > </textarea></div> Currently, I validate this field after the su ...