Increase the height of a div element if it is less than the height of the viewport

I am facing an issue with a div that contains three tabs and a footer. If the content of one tab is shorter than the viewport height, it leaves a blank space below the footer. Here's an example of one tab working correctly.

This is what happens when I switch to another tab

I want the div to extend all the way to the bottom of the page, but I can't seem to figure out how to achieve this.

Below is the code snippet I am using:

<html>
    <head>
        <style>
html, body {
        margin: 0;
        padding: 0;
        height: 100%;
        width: 100%;
    }
        </style>
    </head>
    <body style="padding-top: 3.5rem;">
        <navbar>
            Navbar
        </navbar>
        <div class="container" style="width:100%;display:block;overflow:auto;">
            Tabs and everything else
        </div>
        <footer class="py-5 bg-dark" style="position: relative;bottom: 0;width: 100%;">
            Footer
        </footer>
    </body>
</html>

Just for reference, I am using Bootstrap 4

Answer №1

To ensure that your div takes up the full height of its parent while accounting for a specific header and footer height (e.g., 40px), you can set the min-height property to calc(100%-80px). This way, the div will fill the remaining space after subtracting the header and footer heights. I've included background colors for demonstration purposes:

<html>
    <head>
        <style>
html, body {
        margin: 0;
        padding: 0;
        height: 100%;
        width: 100%;
    }
        </style>
    </head>
    <body style="padding-top: 3.5rem;">
        <navbar style="background-color: yellow; display: block; height: 40px;">
            Navbar
        </navbar>
        <div class="container" style="width: 100%; min-height: calc(100% - 80px); display: block; overflow: auto; background-color: cyan;">
            Tabs and everything else
        </div>
        <footer class="py-5 bg-dark" style="position: relative; bottom: 0; width: 100%; height: 40px; background-color: yellow;">
            Footer
        </footer>
    </body>
</html>

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

Implement SCSS in Next.js 12 using Bootstrap

Ever since updating Next.js to version 12, I've been encountering issues with Bootstrap and SCSS integration. In my project, I have a global.scss file that is imported in the _app.js. Within this file, I include imports for Bootstrap and Bootstrap Ic ...

The sorting icon cannot be substituted with jQuery, AJAX, or PHP

Currently, I am working on implementing "sort tables" using ajax, jquery, and PHP. The sorting function is functioning correctly; however, I need to show/hide the "sorting images". At the moment, only one-sided (descending) sorting is operational because I ...

The resizable function in jQuery is not functioning as expected

Within my project, the initial page includes the following code snippet: html <div id="box"> <div id="header"> <span id="title"></span> <span id="button">X</span> </div> <div id="text"> </div> ...

Ways to automatically style the child divs within a parent div

I'm trying to figure out how to float a parent div with child divs of different widths and heights while maximizing the use of space and not being affected by absolutely positioned elements. For reference, here's an example: http://jsfiddle.net ...

When running the `npm run dev` command, Tailwind does not seem to function

I have been given a task to create forms using tailwindcss, but when I try to run `npm run build`, it doesn't work. Can anyone assist me with this? npm ERR! code ELIFECYCLE npm ERR! errno 9 npm ERR! <a href="/cdn-cgi/l/email-protection" class="__cf ...

Guide on how to set a custom image as the cursor when clicking on an image through javascript

Does anyone know how to use javascript to change the cursor to a custom image by updating the cursor property of the entire page? I'm getting an error in the Chrome console that says: projetFinalPage1.html:626 Uncaught TypeError: Cannot read property ...

How to Override Global CSS in a Freshly Created Angular Component

My CSS skills are a bit rusty and I need some assistance with a project I'm working on. The project includes multiple global CSS files that have properties defined for different tags, such as .btn. However, these global CSS files are causing conflicts ...

CSS Scroll Transitions

I'm currently exploring ways to create div scroll wipes similar to the ones shown in this example. Has anyone successfully achieved this effect using CSS rather than JavaScript? I've been searching for solutions but haven't come across any ...

In Chrome, the height of 100% is not functioning properly within the <div> element

I've been struggling with a problem that I've searched the internet for solutions to, but haven't been able to resolve. The issue revolves around an iframe containing a page that loads specific CSS rules. html, body { position: relative; he ...

Exploring the functionality of setAttribute method in JavaScript

Snippet: activeCell.onclick = function() { console.log(element); element.value = this.value; console.log(element.value); console.log(element); }; Imagine activeCell as a span with value = "678", while element is represented by a simple in ...

Issues with implementing a Bootstrap dropdown list in a Django HTML template

I'm having trouble implementing Bootstrap in my Django project's shared HTML file. The dropdown list isn't functioning properly despite trying various approaches, including using CDN and local Bootstrap files. When I click on the dropdown li ...

Issues with CSS rendering have been encountered on the Facebook page

I'm experiencing an issue with the rollover CSS on Facebook's rendering engine. I'm not sure if I made a mistake in my code or if there are limitations with certain CSS properties on custom Facebook pages. Here is the code I am using: <l ...

Set the background color of a webpage depending on the data retrieved from the database when a specific radio button

I am facing a challenge with my radio buttons that are set to light up green when the page loads. However, I am working on an "order system" where I need a specific button or "locker" to appear red instead of green when the page loads. While I have succes ...

Can you explain the error message "Uncaught TypeError: seats[Symbol.iterator] is not a function" in simpler terms?

I am currently developing a movie seat booking application, but unfortunately, I encountered an error when running the code. According to the Google console, the error is located on line 224 and it states "Uncaught TypeError: seats[Symbol.iterator] is not ...

Uninterrupted Carousel Experience in Bootstrap 4 (Seamless slide transition)

I'm having trouble figuring out how to make a carousel run continuously without pauses between slides. Here's an example of what I'm working with on codeply: .carousel-img-small { width: 80px; height: 80px; margin-right: 2%; } .car ...

make sure the <option> tags fit seamlessly inside a Bootstrap card

I'm currently working on a project using Angular in combination with Bootstrap 4.0. My goal is to integrate <select>, <option>, and <optgroup> elements within a card. Below is the code snippet from the component.html file: <div ...

How can I change the "Return" button on the iOS keyboard to a "Next" button using jQuery or JavaScript?

Currently, I am developing an HTML application and working on implementing it for IOS devices such as the IPAD. Within my application, there are multiple text boxes. Whenever a user clicks on a text box to input text, the keypad appears. On this keypad, ...

Creating dynamic divs with ng-repeat in AngularJS

As someone who is new to angularjs, I am looking for a way to dynamically add a div by clicking on an add icon. I have written some script for this purpose. This is the HTML section: <div ng-show="child" class="childDiv" data-ng-repeat="choice in choi ...

Exploring the world of jQuery and Ajax: Experimenting with implementing a POST method through Ajax and retrieving the response in HTML

Hey guys, I'm currently attempting to set up a basic HTML post method using Ajax. Take a look at the code snippet below: <?PHP function fetchInstagramData($url) { $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => ...

Unable to determine the appropriate signature for calling the date function

<td> {{ fundInfo.startDate | date: "yyyy-MM-dd" }} </td> The issue is located in the primeng-test-b.component.html file under src\app\primeng-test-b directory. ...