Adjust the max-height to occupy the entire available space

One of the challenges I'm facing with my web application is designing the layout in a way that all elements interact seamlessly. The structure is as follows:

<body>
  <nav>       <-- top navigation bar
  <ol>        <-- breadcrumb trail
  <div>       <-- row containing buttons
  <div class="overflow-auto">
    <table>   <-- dynamically expanding table
  </div>
  <footer>    <-- sticky footer 
</body>

As rows are added to the table at runtime, applying the overflow-auto class becomes necessary by setting a specific value for max-height. Interestingly, using a percentage value results in unrestricted growth instead of creating an overflow effect - only pixel values seem to work effectively.

My ultimate objective is to occupy all available space between the preceding div (buttons row) and the persistent footer, adjusting to various factors such as browser dimensions.

In essence, what I aim for is ensuring that users can always see the footer, prompting the overflow function once the table content reaches this point.

I am unsure whether handling this scenario involves employing particular classes or if manual height calculations will be required.

UPDATE

The challenge escalates when incorporating a sidebar into the equation. Below is the complete code snippet:

<body class="vh-100 d-flex flex-column overflow-hidden">
<nav id="nav_top" class="navbar navbar-expand navbar-dark bg-dark static-top">
    <ul class="navbar-nav d-none d-md-inline-block form-inline ml-auto mr-0 mr-md-3 my-2 my-md-0">
        <li class="nav-item">
            <h5>
                <span class="badge badge-secondary">BLABLA</span>
            </h5>
        </li>
    </ul>
</nav>
<div id="wrapper">
    <ul class="sidebar navbar-nav">
        <li class="nav-item active">
            <a class="nav-link" href="index.php">
                <span>NAV 1</span>
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="index.php">
                <span>NAV 2</span>
            </a>
        </li>
    </ul>
    <div id="content-wrapper">
        <div class="container-fluid">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item active">Current page</li>
            </ol>
            <button type="button" class="btn btn-info mb-3">BUTTON</button>
            <div id="content" class="row overflow-auto">
                <div class="col-12 table-responsive">
                    <table id="tableParameters" class="table table-sm">
                        <thead class="thead-light">
                            <tr>
                                <th scope="col">COL 1</th>
                                <th scope="col">COL 2</th>
                                <th scope="col">COL 3</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>table</td>
                                <td>table</td>
                                <td>table</td>
                            </tr>
                            <tr>
                                <td>table</td>
                                <td>table</td>
                                <td>table</td>
                            </tr>
                            <tr>
                                <td>table</td>
                                <td>table</td>
                                <td>table</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

Understanding how the overflow-auto behavior operates within this setup remains unclear. It seems that the presence of row/col divs has an impact on maintaining margins while aiming for the desired result.

Answer №1

If you're looking to achieve this layout, consider utilizing flexbox...

<body class="vh-100 d-flex flex-column overflow-hidden">
  <nav>       <-- top navigation bar -->
  <ol>        <-- breadcrumb navigation -->
  <div>       <-- row containing buttons -->
  <div class="overflow-auto">
    <table>   <-- dynamically growing table -->
  </div>
  <footer class="mt-auto">    <-- fixed footer at the bottom -->
</body>
  • vh-100 - sets the body's height to viewport height
  • d-flex flex-column - styles the body with display:flex and flex-direction:column
  • overflow-hidden - prevents scrolling in the body
  • mt-auto - ensures the footer sticks to the bottom of the page

See a live demonstration here:

This question has actually been addressed previously: Bootstrap 4 row fill remaining height
How to make the row stretch remaining height
Bootstrap 4: Scrollable row, which fills remaining height

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

Adding text on top of images for optimal mobile viewing

I'm struggling to ensure that the text stays contained next to the image. It's working fine on desktop and tablet, but I'm facing challenges with mobile. While I have managed to improve it slightly, I can't figure out what exactly I am ...

HTML: Ensure that a user fills out a minimum of one text box before submission

<tr><td> First Name: </td><td><input type="text" name="FirstName" required></td> </tr> <tr><td> Last Name: </td><td><input type="text" name="LastName" required> </td></tr> ...

Tips for stopping automatic scrolling (universal solution)

Issue or Inquiry I am seeking a way to disable actual scrolling on an element while still utilizing a scrollbar for convenience (avoiding the need for manual JavaScript implementations instead of relying on browser functions). If anyone has an improved s ...

Issue encountered while attempting to retrieve data from a local json file due to Cross-Origin Resource Sharing

I'm attempting to fetch and display the contents of a JSON file on a webpage, but I'm encountering this error message: Access to XMLHttpRequest at 'file:///C:/Users/bobal/Documents/htmlTry/myData.json' from origin 'null' has ...

Update the division by clicking the button with a randomly generated JavaScript string element

Trying to solve a unique problem here as none of the proposed solutions on similar questions have worked for me. Apologies if I'm missing something, I'm new at this. The issue is with loading an empty div on my page using javascript and strings ...

Angular: Ensuring Paypal button does not display twice without a hard reload

I have encountered an issue with a PayPal payment button on my page. The button displays fine when I generate it for the first time, but if I try to generate it again for another order, it doesn't show up. I have to hard reload the page to get it to w ...

UI binder is having difficulty resolving CSS

After creating a search panel for my application using UI binder, I noticed that the desired behavior is not being achieved. Ui.xml <g:HTMLPanel> <c:SimpleContainer> <c:InfoContainerHeader text="{labels.searchFilter}" /> ...

What could be causing my CSS relative positioning to malfunction?

I am struggling to adjust the positioning of my divs using relative and absolute properties. Any advice on how to resolve this issue would be greatly appreciated. Thank you. Example Code: <div id="game"><img src="gta-game.jpg" height="100" width ...

What is the best way to toggle a specific div element within an ng-repeat loop?

I have a list of products. When I click on a product, it should be added to the database. If I click on the same product again, it should be removed from the database. I am toggling the wishlistFlag using ng-click. This works correctly for one div element, ...

Issue with Material Design Lite input floating label not functioning properly post page navigation

I am currently developing a mobile hybrid application using Material Design Lite, but I have run into a small issue. When I add input field elements to my pages, the floating text and placeholder do not function properly. In my application, I am utilizing ...

What is the best way to make an exit pop up disappear when clicking on any area?

I'm new to programming in JavaScript and jQuery and I wanted to implement an exit pop-up feature. While I came across a helpful tutorial online, I encountered an issue where users could only exit by clicking on the "X" button. I want them to be able t ...

As I scroll past the top or bottom of the page, the body's background color transitions to a new shade

I am encountering an issue with my next.js app where the body background color is set to black. Here is the code in globals.css: body { background-color: black; padding: 0; margin: 0; font-family: 'Titillium Web', sans-serif; } However, ...

Associate information with HTML elements

I've come across this question multiple times, but the solutions are mostly focused on HTML5. My DOCTYPE declaration is: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> I'm looking t ...

When using ngClass and the has-error class on load, the class will still be loaded even if the expression evaluates

When attempting to load the has-error class from Bootstrap using ng-class with a condition on a variable injected to the controller from my factory, I encounter an issue where even though the initial value of the variable is false, the has-error class load ...

What is the best method for creating a distinctive identifier in HTML and jQuery?

Coding in HTML: @foreach($permission->childs as $subMenu) <tr> <td>{{$subMenu -> id}}</td> <td> &nbsp; &nbsp;{{$subMenu -> display_name}}</td> <td ...

Creating unique ID tags using AngularJS

I am struggling with creating an HTML structure that looks like this: <ul> <li id="r1_1">Root node 1 <ul> <li id="child_node_1">Child node 1</li> <li id="child_node_2">Child node 2</ ...

Creating an HTML tag from Angular using TypeScript

Looking at the Angular TypeScript code below, I am trying to reference the divisions mentioned in the HTML code posted below using document.getElementById. However, the log statement results in null. Could you please advise on the correct way to reference ...

Creating artwork: How to resize images without losing clarity

Struggling to display an image in a canvas element that needs to be a certain percentage of its parent container's width. Despite my efforts, the image seems to blur once added to the canvas, which is not the desired effect. I attempted to disable th ...

Can a PHP file be used in the src attribute of an HTML5 audio element?

Within my PHP code, I am attempting to include an audio tag like this: '<audio src="song.php" />'.$fallback.'</audio>' I have experimented with various approaches in the "song.php" file, but unfortunately, none of them hav ...

The issue with Internet Explorer failing to adhere to the restrictions set on maximum width and

I'm attempting to scale my images precisely using CSS: HTML: <div id="thumbnail-container"> <img src="sample-pic.jpg"/> </div> CSS: #thumbnail-container img { max-height: 230px; max-width: 200px; } In this scenario, ...