Tips for keeping your container from expanding due to a bootstrap table

Check out this Codepen example for reference: https://codepen.io/anthonyhvelazquez/pen/oNjPrgQ

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>

  </div>
</nav>
<div class="container-fluid">
  <div class="row justify-content-center">
    <div class="col-md-3">
      <div class="content h-100" style="background: red">
        Left Side Navigation
      </div>
    </div>
    <div class="col-md-9">
      <div class="table-responsive">
                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>Sheet Name</th>
                            </tr>
                        </thead>
                        <tbody>
                          <tr>
                            <td>Filler</td>
                          </tr>
                          <tr>
                            <td>Filler</td>
                          </tr>
                          <tr>
                            <td>Filler</td>
                          </tr>
                          <tr>
                            <td>Filler</td>
                          </tr>
                          <tr>
                            <td>Filler</td>
                          </tr>
                          <tr>
                            <td>Filler</td>
                          </tr>
                          <tr>
                            <td>Filler</td>
                          </tr>
                      </tbody>
        </table>
    </div>
  </div>
</div>

I have a layout with a left-side navigation panel and a table on the right. However, I'm looking to ensure that the container stays within specific height parameters regardless of the content inside it.

  • The goal is to keep the container's height as (screen height - navbar height) at all times, even if the content overflows.

  • The table should expand to fill the container, even if its content is insufficient to do so.

  • If the table exceeds the container's limit, there should be a vertical scroll with sticky table headers at the top.

Any suggestions on achieving this outcome or implementing a more responsive design approach?

Answer №1

In my opinion, the first step is to obtain the viewport dimensions and then subtract the height of the navbar from that.

To achieve a sticky table header, you can apply CSS styles like this:

.table-wrapper-scroll-y {
  display: block;
}

.tableFixHead td {
  padding: 8px 16px;
}

.tableFixHead th {
  position: sticky;
  top: 0;
}

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

Display or conceal all sections based on selected dropdown options within the Elementor plugin

I have a dropdown menu with 9 different sections underneath 1. Section id=Hige x 3 2. Section id=Medium x 3 3. Section id=Low x 3 My goal is to show only the sections that correspond to the selection made in the dropdown menu. I am using jQuery to achi ...

What is the best way to increase numerical values within strings in jQuery or JavaScript?

I am facing an issue where I need the last digit in a string to increment, for example, from ABC123-DE45-000 to ABC123-DE45-001. I tried implementing code to achieve this but the increment happens from 000 to 1 instead of adding leading zeros as required. ...

Upon selecting a hyperlink, the function's value ought to be saved within a text box

Some programming languages I'm working with are PHP, Javascript, and HTML I've created a PHP function that is stored in page2.php: function pot() { does something; returns a value; } In another page (page1.php), there is a link and a textbox: ...

Button for Dark Mode

I have created a button that is supposed to switch the background color from black to blue. However, I am having trouble finding an easy solution to do so. Here is my HTML file: <div style="background-color: #161624; width: 100%; height: 20%; " ...

Circular graphs displaying percentages at their center, illustrating the distribution of checked checkboxes across various categories

Looking for a JavaScript script that displays results in the form of circles with percentage values at their centers, based on the number of checkboxes checked in different categories. The circle radius should be determined by the percentage values - for e ...

The content div sits atop the full-width image instead of being displaced downwards

Featuring a stunning full-width image: .image { background-image: url(http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg); background-position: center center; background-repeat: !important; position: absolute; ...

Shifting Transition for Customer Reviews

I am working on implementing a testimonial slider on my webpage located at . I am trying to make it automatically slide by itself, but have been unsuccessful so far. I would appreciate if you could visit the demo page on my website and help identify what ...

Is there a way to identify when a radio button's value has changed without having to submit the form again?

Within this form, I have 2 radio buttons: <form action='' method='post' onsubmit='return checkForm(this, event)'> <input type = 'radio' name='allow' value='allow' checked>Allow ...

Issue when clicking on multiple dropdown menus

My backbone.js app can be viewed here: http://jsfiddle.net/TD9Wj/. While the default code for Dropit.js works perfectly, I am currently trying to make modifications so that the dropdown closes when the trigger is clicked. Essentially, clicking on "menu" s ...

Tips for resolving issues with JS and JQuery not functioning properly in a Chrome extension

Currently configuring a chrome extension and have successfully constructed the settings menu with functional CSS and HTML. Utilizing this button from Codepen, which confirms error-free code via https://i.sstatic.net/0yG0l.png. How should I define the fun ...

Form that is generated dynamically is malfunctioning

Having issues with an AJAX function that dynamically populates a list of elements from the database. Each element includes a display picture and a name, along with a hidden field containing a variable captured on another page via POST to display image and ...

Choosing pseudo-elements with CSS styling rules

I have been utilizing the Brave browser to block online ads. However, certain websites have found a way to insert ads into their HTML on the server-side, bypassing my ad-blocking efforts in Brave. Currently, Brave only offers the ability to block elements ...

Angular causes HTML Dropdown to vanish once a null value is assigned

In my scenario, I have two variables named power and mainPower. Both of these variables essentially represent the same concept, with mainPower storing an ID of type Long in the backend, while power contains all attributes of this data transfer object. The ...

Arrange documents according to the final two characters

My method for collecting files from a folder involves using some Smarty code: {assign var=files value="uploads/Documenten/GPS-Tracks/*.html"|glob} {if count($files)} <ul> {foreach from=$files item='file'} {assign v ...

PHP: The issue with displaying array values in an HTML select within a form using a foreach loop

I am currently working with an array containing a list of countries. $country_list = array( "Afghanistan", "Albania", "Algeria", "Andorra", "Angola" }; I want to display these countries using a select element in my form <select ...

Obtaining the data attribute or id of a clicked element in Bootstrap 2.3.2 modal and jQuery 1.7.1: A step-by-step guide

Unfortunately, I am restricted to using bootstrap 2.3.2 modal along with jquery 1.7.1. Below is the code snippet for three conference rooms. When an element is clicked, a modal popup appears correctly, but there is a struggle in fetching t ...

PHP-generated HTML often contains unnecessary and excessive indentation

I'm trying to adjust the indentation of my HTML generated by PHP, but I'm facing issues removing some unwanted indentations. Take a look at this snippet from the HTML source: <table id="structure"> <tr> <td id="navigation"> ...

Leveraging JavaScript's Document.write() function to generate an HTML hyperlink

I am struggling with a URL stored in a variable (var URL). My initial attempt was this: document.write("<a href='"+url+"'>LINK</a>"); Unfortunately, it is not working as expected. Any suggestions on how to fix this? This is the ex ...

PHP POST request with an additional value being sent

Greetings as this is my debut post! Currently, I am facing a challenge in my project. As seen in the screenshot provided, I have several names fetched from the database and displayed in the main menu. Upon clicking the "modal" button, a Bootstrap modal wi ...

Refreshed the page following a setAttribute function call in Javascript

I have successfully implemented a function to switch between light and dark mode on my webpage using VueJS. However, I am facing an issue with the code: <a @click="toggleTheme" class="switch-mode" href> <div class=&q ...