The Bootstrap 4 container with a height of 100vh is overflowing when placed within a column with

I'm still learning the ropes of bootstrap. I have a bootstrap 4 page with three columns, and in the middle column, there's a container housing 4 images in a grid format. My goal is to have this container take up as much space as possible on larger screens while maintaining the aspect ratio of the images inside. Currently, I've been experimenting with manually setting the column width (e.g., col-lg-5), but it's hit or miss depending on the screen's aspect ratio. The auto-width option results in either the image container not filling the entire height or overflowing outside the view. Setting the height of the image container to 100% using max-height: 100vh; seemed promising, but the rows within the container didn't scale accordingly and instead overflowed vertically.

For reference, here's an example:

<div class="container-fluid">
    <div class="row justify-content-center">
        <div class="col-auto" style="background-color:red;">
            <h2>Column 1</h2>
        </div>
        <!-- I want the content in this column to take up 100% height on large screens, but 100% width on small screens (columns stack) -->
        <div class="col-auto" style="background-color:green;">
            <h2>Column 2</h2>
            <div id="img-container" class="container" style="max-height:100vh;">
                <div class="row">
                    <div class="col p-0">
                        <img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png">
                    </div>
                    <div class="col p-0">
                        <img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png">
                    </div>
                </div>
                <div class="row">
                    <div class="col p-0">
                        <img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png">
                    </div>
                    <div class="col p-0">
                        <img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-auto" style="background-color:blue;">
            <h2>Column 3</h2>
        </div>
    </div>
</div>

Current: https://i.sstatic.net/stGpX.png Currently, the images are overflowing the container, and I can't seem to find the right solution for proper scaling.

Desired outcome: https://i.sstatic.net/PwLPR.png I aim for the image container to always fill 100% height with automatic width until all available space is utilized on the sides. On smaller screens, the three columns should stack vertically, with column 2 occupying 100% width.

Answer №1

An innovative approach that might just do the trick

  1. Extra care needed for smaller screen sizes
  2. The reason for the limited expansion beyond a certain width is due to the inner
    <div id="img-container" class="container">
    . Altering it to
    <div id="img-container" class="container-fluid">
    could provide more flexibility
  3. The max-height:46vh constraint is in place to accommodate the header of Column 2. Calculating this dynamically on-the-fly may yield better results

Code snippet

 <head>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>

<div class="container-fluid"  style="max-height:100vh;">
    <div class="row justify-content-center">
        <div class="col-auto" style="background-color:red;">
            <h2>Column 1</h2>
        </div>
        <!-- The content in this column should occupy 100% height on large screens and 100% width on small screens (stacked columns) -->
        <div class="col-auto" style="background-color:green;" >
            <h2 class="header-2">Column 2</h2>
            <div id="img-container" class="container">
                <div class="row">
                    <div class="col p-0">
                        <img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png" style="max-height:46vh;">
                    </div>
                    <div class="col p-0">
                        <img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png" style="max-height:46vh;">
                    </div>
                </div>
                <div class="row">
                    <div class="col p-0">
                        <img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png" style="max-height:46vh;">
                    </div>
                    <div class="col p-0">
                        <img class="img-fluid" src="http://climate.met.psu.edu/ewall/test.png" style="max-height:46vh;">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-auto" style="background-color:blue;">
            <h2>Column 3</h2>
        </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

Set the height of the unordered list (ul) to be

I came across a design on Facebook that resembles a timeline, but I am having trouble adjusting the height of the ul element. <ul class="timeline">...</ul> I want the line in the middle to fill the height of the page even when there is less c ...

Nginx and Django encountering issues with loading css files on a production server

I've come across several similar posts, but none of the solutions seem to work for me. Every time I load my static files, the browser throws errors like these: When I collect static files, everything works fine. Even running findstatic points me to t ...

Obtaining added HTML content following an AJAX request using JQuery

After making an ajax request to append a new entry, everything seems to be working fine. However, I noticed that the design is not displaying correctly. Upon inspection, it seems that the HTML has been loaded properly, but for some reason accessing the dat ...

AngularJS fetches the 'compiled HTML'

If I have this angularjs DOM structure <div ng-init="isRed = true" ng-class="{'red': isRed == true, 'black': isRed == false}"> ... content </div> How can I obtain the 'compiled' version of this on a cl ...

The CSS styles do not seem to be taking effect on the Bootstrap

Here's a snippet of code extracted from my website's html and css files. My intention is to make the navbar slightly transparent with centered links, but for some reason, the css styles are not applying correctly to the navbar. HTML <body ...

I'm facing an issue where I am unable to access an element by its ID in a c++ application, despite everything else functioning correctly

I am currently working on some HTML, CSS, and JS tasks and I have encountered a problem. For some reason, I am unable to access elements in JavaScript using getElementById or jQuery tags... nothing seems to work. Here is the HTML code for my element: < ...

Determining when all textures have successfully loaded in Three.js and ensuring there are no lingering black rectangles

I'm currently developing a web platform that allows users to customize and preview 3D house models. If the user's browser doesn't support WebGL, the server renders the house and sends screenshots to the client. However, if the screenshots ar ...

Press the list item corresponding to a specific name by utilizing JavaScript in Selenium with Python

I am currently developing a web form and facing a challenge with clicking on a specific li within a ul based on the text of the list item. For example, in the scenario below, I need to click on the option labeled "Your Employer". While I have successfully ...

HTML5 images not loading correctly upon initial load despite utilizing image.onload

Currently, I am developing a webapp using EaselJS and encountering an issue where, upon the initial load after clearing my cache, the images are loading in the top left corner at their default size (x:0, y:0, scale:1) instead of the specified position. I u ...

Incorrect font display occurring exclusively on Windows Chrome

There seems to be an issue with the Google served Open Sans font on my website, specifically with Win Chrome where the font appears thick and ugly. However, when I tested it on Win FF and Safari, everything seemed fine. The font also displays correctly on ...

The table will remain empty for eternity as the page is being loaded using ngRoute

Currently, I am utilising Angular routers. app.config(function($routeProvider) { $routeProvider .when('/comment/list', { templateUrl: 'commentList.htm', controller: 'mainController' }) }); ...

Issue with line height using Material-UI grid alignment: Ensure line heights are unitless for proper alignment

Encountering a common error in ReactJs projects: Error: Material-UI: unsupported non-unitless line height with grid alignment. Use unitless line heights instead. A snippet of the code where the error occurs: const breakpoints = createBreakpoints({}); le ...

Ways to create distance between 2 select elements with CSS?

Having trouble with the spacing between two select fields on a form? Specifically, you want the start time, start time meridian, end time, and end time meridian all in a single line. Any suggestions or solutions to this issue would be greatly appreciated! ...

Using Javascript to dynamically swap images within a div as the user scrolls

Can someone help me achieve a similar image scrolling effect like the one on the left side of this website: I am looking to change the image inside a div as I scroll and ensure that the page doesn't scroll further until all the images have been scrol ...

I'm looking for a way to retrieve an object from a select element using AngularJS. Can

I am working with a select HTML element that looks like this: <select required="" ng-model="studentGroup"> <option value="" selected="">--select group--</option> <option value="1">java 15-1</option> <option value="2">ja ...

Trouble with CSS positioned image rendering in Internet Explorer? Z-index not solving the issue?

I've been working on a timeline project where the completed sections should have a green background with a check mark image in the foreground. It appears correctly in Firefox, Chrome, and Safari. However, in IE 7 and 8 (and possibly 9), the layout is ...

Implementing login functionality in an Angular application with the help of Kinvey.Social and utilizing the Promise API

I have been utilizing the Kinvey HTML5 library in an attempt to create a client-side application that integrates Google identities for Login. While the Oauth transaction appears to be functioning properly, I am encountering an issue with toggling the visib ...

Conceal series of images with a click; reveal them again once completed

I'm working on a layout featuring overlapping images and I'm looking to create a hide-and-seek effect where the images are hidden one by one when clicked, and then shown in reverse order until all of them are visible again – essentially creatin ...

Unable to retrieve background position using jQuery .css() without needing !important in CSS

Could someone please explain why the jQuery .css() method is returning 0% 0% for elements with a background position defined in the inspector and style sheet? I'm puzzled as to why adding !important to the rule makes it work, but not without. The jQ ...

The looping functionality in Swiperjs is not working properly for sliders

Encountering some issues with the loop setting for swiper. The problem is that it stops sliding before entering a second loop, always halting at a certain point. I have never worked with swiper before, so I am unsure if this is the intended behavior or not ...