Adjustable columns that fill the rest of the screen's height below a navigation bar

I am facing an issue with my non-fixed navbar and two-column layout when testing the responsiveness on a mobile screen size. I need Column A to fill the remaining viewport's height, while Column B should move under Column A without hardcoding any values like subtracting the navbar's height. I attempted using Flexbox to achieve this, but so far have been unsuccessful as both columns appear in the viewport instead. Currently, I am utilizing Bootstrap for the responsiveness of the layout.

Here is an illustration depicting my problem. Below is the code snippet that I have been working with:

.flex-container {
            display: flex;
            flex-direction: column;
        }

        #content {
            flex-grow: 1;
        }

        #row {
            flex-grow: 1; max-width: 100vw;
        }

        #col1 {
            background-color: dimgrey;color: white;
        }

        #col2 {
            background-color:darkslategrey;color: white
        }
<!doctype html>
        <html lang="en">
          <head>
            <!-- Required meta tags -->
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

            <!-- Bootstrap CSS -->
            <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

            <title>Web title</title>
          </head>
          <body>
            <div class="vh-100 flex-container">
              <nav class="navbar navbar-dark bg-dark">
                <div class="container px-0">
                  <span class="navbar-brand mb-0 h1">Navbar title</span>
                </div>
              </nav>
              <div id="content" class="container flex-container px-0">
                  <div id="row" class="row mx-0">
                    <div id="col1" class="col-sm px-0">
                      Column 1 content
                    </div>
                    <div id="col2" class="col-sm px-0">
                      Column 2 content
                    </div>
                  </div>
              </div>
            </div>

            <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
            <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30405f404055421e5a4370011e01061e00">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
            <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
          </body>
        </html>

Answer №1

Upon analyzing your inquiry, it appears that you wish for the first child element to occupy full height and have a second child appear upon scrolling past the first one.

Since your content is utilizing flex: 1, which inherently takes up the entire remaining height, you can leverage this feature to achieve your desired outcome. Simply set the height of both #row and its children to 100% like so:

#row, #row > * {
    height: 100%
}

By implementing this adjustment, you will effectively establish the height of #row and its respective children to span 100% of the available space. This arrangement will work seamlessly within the mobile layout, providing you with the results you seek.

I trust that this solution addresses your concerns adequately.

Answer №2

To ensure that the height is set to 100vh only on smaller screen widths, you would utilize a media query...

@media (max-width: 576px) {
    .min-100 {
        min-height: 100vh;
    }
}

Answer №3

If you're searching for a solution that adapts to different screen sizes, consider implementing a responsive design. One way to achieve this is by using Media Queries to control the layout based on device dimensions. When it comes to adding interactive elements like a carousel, Bootstrap offers a convenient solution.

For more information on how to implement a carousel in your project, check out https://getbootstrap.com/docs/4.4/components/carousel/

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

Scroll horizontally on a webpage using drag with JavaScript

I have been working on a unique horizontal website design that allows users to scroll horizontally by dragging the screen. I managed to successfully implement the horizontal scrolling feature, but I am facing difficulties in adding the horizontal drag-to-s ...

Having trouble with the Slide Toggle menu closing unexpectedly?

$('span.nav-btn').click(function () { $('ul#menu').slideToggle(); }) $(window).resize(function () { if ( $(window).width() > 900) { $('ul#menu').removeAttr('style') } }); $('spa ...

Extension for Chrome that switches between active and inactive modes

I have been attempting to create an extension that can toggle the functionality of another specific extension on and off. Despite numerous attempts, I have not been able to find a solution that works effectively. Essentially, my extension displays a popup ...

The single controller can now showcase various notification styles for operations such as insertion, updating, or error handling

I need to display notifications to the user based on three different scenarios using a controller. When data is successfully inserted When data is successfully updated In case of an error For each scenario, I want to show a different style of notificati ...

Enable users to upload pictures along with text descriptions

I want to enhance the user experience on my website by enabling them to upload images along with captions. Currently, users can upload images but they don't have the option to add a caption. I know I need to implement a database for this functionality ...

Show pictures from a distant server on a mobile application with PhoneGap

Currently, I am utilizing PhoneGap to develop an HTML5 news application for Android, iOS, and Blackberry platforms. This unique app is designed to fetch articles from a website that was constructed using PHP. Each article features a title, content, and im ...

a practical guide on implementing overflow-x in the row class

How can I implement a row scroll overflow on the x-axis for columns 5, 6, and 7? <div class="container-fluid"> <div class="row"> <div class="col-4">col 1</div> <div class="col-4">col 2</div> ...

What is the best way to eliminate a specific set of characters from a string using TypeScript?

Imagine you have the following lines of code stored in a string variable: let images='<img alt="image1" height="200" src="image1.jpg" width="800"> <img alt="image2" src="image2.jpg" height="501" width="1233"> <img alt="im ...

calculation of progress bar advancement

I want to make the progress bar in my game responsive to changes in the winning score. Currently, it moves from 0% to 100%, which is equivalent to 100 points - the default winning score. But I need the progress bar to adjust accordingly based on the user-i ...

Is there a way for me to execute a function multiple times in a continuous manner?

I am attempting to create a blinking box by calling a function within itself. The function I have is as follows: $(document).ready(function(){ $("button").click(function(){ $("#div1").fadeToggle("slow"); }); }); <script src="https://a ...

Creating a smooth transition effect on text length using Javascript and CSS: Fading the text as it

I have been searching everywhere for a solution to my issue, but I haven't found it yet. I keep coming across methods to fade text on and off on load, which is not what I need. My goal is to fade some text on the same line, and I have created a mockup ...

Turn off scrolling for the body content without removing the scrollbar visibility

Whenever I click a thumbnail, a div overlay box appears on top: .view-overlay { display:none; position:fixed; top:0; left:0; right:0; bottom:0; overflow-y:scroll; background-color:rgba(0,0,0,0.7); z-index:999; } Some browsers with non-f ...

Occasionally, altering the visibility of an element right before submitting a form in Safari may not be effective

Below is the HTML element I'm using to show a loading spinner in my app, with mostly Bootstrap classes: <div id="loadSpinner" class="overlay d-flex justify-content-center invisible"> ... </div> Here is the form on vi ...

Fit the image to fill the available space and position it in the center for maximum impact

I'm currently working on a single page application where I need to display an image that fills up as much available space as possible: Priority: maintain the aspect ratio Avoid cropping the image Stretch the image horizontally and/or vertically (with ...

The functionality of AJAX is triggered only on the second click

On my index.html page, I'm attempting to implement a basic AJAX functionality. When clicking on an anchor tag, the text will be sent to a PHP page called data.php, which will then display the clicked page. The code is functional, but there seems to be ...

How are these background images able to remain in a fixed position like this?

Trying to name this question correctly was a bit tricky. Hopefully I got it right. I have a new client and they want their website to have a similar feel to . If you check out the index page and scroll down, there's this cool 'smooth animation& ...

Creating a responsive design for Bootstrap divs

I am trying to display 5 images in one row with 5 columns. I have used the following CSS for this layout: .col-half-offset { margin-left: 4.166666667% } This setup works well on the web, but on mobile devices, the layout does not di ...

Ensure consistency in the heights of div elements, even when the images contained within have varying heights

I created a bootstrap webpage with a row of DIVs, each containing an image. As I resize the browser window, I noticed that the height of the first two DIVs remains consistent, but the third div's height varies because the image is only 50 pixels high. ...

Display the div without using javascript/jquery if the radio button is chosen

Could someone help me find a solution similar to the one mentioned here: If Radio Button is Selected Show Div I am specifically looking for a way to achieve this using only HTML and CSS, without involving JavaScript or jQuery. Any suggestions would be gre ...

Hovering over the top menu items in AngularJS will reveal dropdown submenus that will remain visible even when moving the cursor

I am facing an issue where my top menu has links that display a dropdown of additional menu items upon hovering. I have attempted to use onmouseover and onmouseleave events to control the visibility of the sub menu. However, I have encountered a problem ...