Ensure that the table container occupies the remaining viewport height without causing vertical scrolling in the window, while also enabling vertical scroll within the table itself

I am seeking a solution to create a table that fills the remaining height without causing a vertical scroll in the browser. My goal is for the table itself or its container to have a vertical scroll instead.

I found guidance from another post on how to make a div fill the height of the remaining screen space: Make a div fill the height of the remaining screen space

To achieve this, I attempted to enclose the table within a container div and set it to 100% max-height, but unfortunately, this approach did not work:

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.box {
  display: flex;
  flex-flow: column;
  height: 100%;
}

.box .row {
  border: 2px dotted grey;
}

.box .row.header {
  flex: 0 1 auto;
  background-color: deeppink;
}

.box .row.content {
  flex: 1 1 auto;
  background-color: violet;
}

table,
th,
td {
  border: 1px solid black;
}

#table-container {
  background-color: yellow;
  max-height: 100%;
  overflow-y: scroll;
}
<div class="box">
  <div class="row header">
    <p><b>header</b>
      <br />
      <br />(sized to content)</p>
  </div>
  <div class="row content">
    <p>
      <b>content</b> (fills remaining space)
    </p>
    <div id="table-container">
      <table>
        <thead>
          <tr>
            <th>Month</th>
            <th>Savings</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>January</td>
            <td>$100</td>
          </tr>
          <tr>
            // Additional rows of data...
          </tbody>
      </table>
    </div>
  </div>
</div>

It is important to note that there are other elements within the row containing the table, like the <p> in the code snippet, and below it lies the table container.

Answer №1

If you want to address this issue, simply update the max-height in table-container to:

max-height: 80vh;

That should prevent your page from scrolling excessively!

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

What is the process for incorporating a Bootstrap link into a specific ReactJS file?

In my current project using React JS, I found the need to incorporate Bootstrap in certain pages. To do this, I initially placed the following code snippet in the Public folder within index.html: <link rel="stylesheet" href="https://netdna.bootstrapc ...

How to use puppeteer to extract images from HTML that have alt attributes

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 nopadding text-center"><!-- Start Product Photo --><div class="row"><img src="/products/ca/downloads/images/54631.jpg" alt="Product image 1">&l ...

What is the best way to transform the hashMap<String, String> into a practical JavaScript object?

To make a long story short. The backend team has provided me with a hashMap that looks like this: {12=Other Services (Assisted), 2=Other Services, 4=Collect, 17=Get New (For Me), 19=Get New (For My Business)} As a front-end developer, I am not familiar ...

Vuetify's offset feature seems to be malfunctioning as it does not

I'm facing an issue with the <v-flex> element in my code, specifically with the offset property not responding as expected. Despite following the recommended layout from the vuetify docs, I can't seem to get it right. Below you can see the ...

Displaying jQuery content tabs with excessive whitespace visible

My project utilizes a jQuery content tab plugin featuring 6 tabs with different content sections (Company, The founders, Team, Accolades, Careers, Philosophy). I am encountering an issue in Chrome where clicking on the Company tab after any other tab res ...

Add a pair of assorted div elements to a shared container

I have two different sections with classes named "red" and "blue". By default, these sections are hidden. I want to duplicate them and display them in a single container named "cont". The red button appends the red section and the blue button appends the b ...

Can one determine if a webpage is being displayed within an Infragistics igDialog?

Occasionally, my web page is displayed without a container and other times it's embedded within an igDialog of another container page, based on the user's navigation throughout our web application. Is there a way, using pure javascript or jQuery ...

Using JQuery to find and update elements in the DOM

My goal with JQuery is to have the select attribute removed from the Default.aspx li element and added to the Feedback.aspx li element when a user clicks on a link like Feedback.aspx. <ul id="main_menu" class="main_menu ui-sortable"> < ...

Designing Buttons and Titles for the Login Page

I'm currently working on developing a straightforward login page in react native and I've encountered some difficulties with styling. Does anyone have tips on how to center the text on the button? Also, is there a way to move the INSTARIDE text ...

Decrease the gap between the <hr> and <div> elements

I currently have multiple div tags with hr tags in between, resulting in automatic spacing. I am looking to decrease this space. Please view the image link provided below for reference. [I am aiming to minimize the gap indicated by the arrow] Additionally ...

Scrolling of div restricted to only horizontal direction

I'm attempting to create a div that contains a paragraph within it. My goal is to have the ability to scroll down when there is overflow due to the content of the paragraph, thus preventing it from extending beyond the boundaries of the DIV. However, ...

Resolving a responsive bug in HTML and CSS

While I was in the process of optimizing my personal website for smartphones, I came across a bug that is visible in this image: https://i.sstatic.net/aFDjd.png https://i.sstatic.net/5oDRr.png The page width exceeds the screen size. Upon inspection using ...

Subsequent line in hta/html

I have been attempting to achieve the following output: Line 1 Line 2 Line 3 My attempts so far have included: <p>Line 1 Line 2 Line 3</p> Unfortunately, this results in: Line 1 Line 2 Line 3 I also tried the following method: <p>L ...

Bulma's Grid System Spans Columns Across the Entire Viewport

Utilizing the Bulma CSS framework. In my attempt to arrange some elements, I am puzzled as to why, in a desktop view, the items do not transition to the next row once they exceed the viewport. Below is a snippet of code along with a link to a JS Bin exam ...

Ways to eliminate dates from the text of listed items

Before finalizing their registration, users on our site are shown a review page. This panel displays all the items they have selected, creating a unique and variable list for each individual. However, each item in the list starts with a distracting date/ti ...

Clicking on the button has no effect whatsoever

I'm currently dealing with a button on my webpage that seems to be causing me some trouble: <script> function changeMap() { container.setMap(oMap); } </script> <button onClick="changeMap"> Click here </button> Upon inspe ...

Attempting to navigate the world of AJAX and PHP

My experience with AJAX is limited, but I am currently working on a project that requires a form to submit data without refreshing the page. The goal is to display the result in a modal window instead. To achieve this functionality, I understand that imple ...

The data in MongoDB is organized using unique identifiers called ObjectId

I am currently working on a MEAN Crud project and encountering some issues. Despite the data being received in the mongodb, it is displaying as an objectId instead of the actual content. You can see this issue in the image below: https://i.stack.imgur.com ...

Displaying images in Ionic from a JSON URL source

I am having trouble getting an image from a JSON to display on an Ionic card. Although I can see the JSON response in the console log, the image is not showing up on the card, leaving it blank. It seems like I'm making a mistake in the HTML code. Any ...

Experiencing an issue of receiving an undefined value while attempting to retrieve a value from an input box

HTML: <input value='Rename' type='button' onclick='RenameGlobalPhase({$row['id']});' <span id='renameGlobalPhase{$row['id']}'>" . $row['phase'] . "</span> Below you wil ...