Tips for maintaining tbody scrolling while adjusting max height to percentage?

I have implemented a scrolling method within the tbody element by using the following CSS:

tbody {
      display:block;
      max-height:575px;
      overflow-y:scroll;
      }
thead, tbody tr {
      display:table;
      width:100%;
      table-layout:fixed;
      }

However, I am facing an issue where the fixed height setting is causing inconsistencies across different devices. Unfortunately, I do not have the time to adapt the code for each potential device. Ideally, I would like the tbody element to fill 100% of its parent while still allowing it to scroll independently. Is there a way to achieve this?

I have researched various solutions for locking headers in place while scrolling and have tried several options, but none have met my specific requirements. The code sample above is the closest I have come to what I need, although the max-height property is not working as desired.

Answer №1

To implement this feature, you can utilize CSS Flexbox

If your HTML structure resembles the following:

<table>
  <thead></thead>

  <tbody></tbody>
</table>

The provided CSS code will establish a fixed header and a scrollable body section. The body content will dynamically occupy the remaining page space.

table {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

tbody {
  flex: 1;
  overflow-y: scroll;
}

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 information depending on the anchor; reveal the first one automatically

Utilizing only HTML and CSS, we can achieve the functionality of displaying and hiding content using an anchor tag: #red { background: red; } #blue { background: blue; } #green { background: green; } .box { width: 200px; height: 200px; display: no ...

Eliminating classes with jQuery through the use of logical operators

I have been trying out some experiments and I got curious if there is a way to eliminate a class from a div in all divs except the specified one: $(function() { $('#tab-2').click(function() { ...

Looping within a JavaScript object is like exploring a labyrinth of

I am in the process of refactoring some code to update page content on a set interval. Currently, I am iterating through an original JSON object to create a subset of content related to specific pages based on their IDs. Upon logging the data, I can confir ...

"Returning undefined: The outcome of using jQuery's .html() method on

I am having an issue with the JavaScript function I have created to load content from another URL into the current document. For some reason, both contentHtml and menuHtml variables are showing as undefined. Can someone please help me identify where I we ...

Transform a desktop site into a mobile-friendly version

After completing my website, I noticed that it looks great when viewed on a desktop browser. Unfortunately, the mobile version is completely unreadable... I really need a mobile-friendly version of my site but don't have the time or knowledge to lear ...

Form a figure using the others

After spending three days attempting to create a dynamic figure within the other figures, the task remains elusive. I tried using THREE.ExtrudeGeometry, but ran into a roadblock: The "tail" should have a radius: Unfortunately, none of the parameters in ...

Alignment customization for Bootstrap 4 dropdown menus

I'm currently working on creating a unique custom drop-down menu design. I had an initial idea in mind which looked like this: https://i.sstatic.net/CFqdi.png However, the final outcome turned out like this: https://i.sstatic.net/je21s.png I' ...

Is the PNG image displaying poorly in the IE10 browser?

My application features a PNG image with actual dimensions of 300px X 300px. I am using a 20% scale of this image as an input image button, which displays correctly in Mozilla and Chrome browsers. However, in IE, the image appears distorted. Please refer t ...

Implementing conditional ng-show based on checkbox status in AngularJS

I have created this code to filter out the out-of-stock products using ng-show. When the checkbox is checked, only the available products should be displayed. HTML: <input type="checkbox" id="chkStock" value="Exclude Out of Stock" ng-model="exclude" / ...

Safari showing white flash upon setting background-image src using Intersection Observer?

I've done extensive research but I'm still struggling to solve this issue. It only seems to be happening on Safari (Mac & iOS), while everything works smoothly on Chrome, Firefox, Edge, and other browsers. UPDATE: The flickering problem also per ...

Angular 10 is displaying a message indicating that a font has not been

I'm facing an error in my Angular project when trying to add a font to the SCSS file. How can I resolve this issue? style.scss: @import "~@angular/material/theming"; @include mat-core(); $PWP-primary: mat-palette($mat-indigo); $PWP-accent: ...

How to Customize Auto Complete Background Color of Selected Items in Bootstrap 4 Input Controls?

I'm currently struggling to figure out how to override the default white background color of a form control's autocomplete in Bootstrap. The white background doesn't align well with my dark theme. Whenever I enter something into an input fi ...

Learn how to extract JSON information from a URL and integrate it into either a table or dropdown in Vue.js

Looking to retrieve a JSON data array from a URL and utilize it to populate either a table or dropdown with Vue.js and Axios. Here is the link where I intend to fetch the data. Any advice on how to accomplish this? https://jsonplaceholder.typicode.com/us ...

Utilizing jQuery and Ajax to submit a form using the POST method

I am facing an issue while trying to submit data from a form using jQuery and Ajax. Despite my efforts, the PHP script does not register the submission as the MySQL code fails to run. I suspect that there might be an issue with the HTML setup preventing th ...

Utilize jQuery to locate the class that appears earlier in the DOM tree

Can someone assist me with retrieving the previous occurrence of a class within a specific portion of the Dom Tree using jQuery? If there is no previous occurrence, I would like to be informed about it. To clarify further, by "previous occurrence" I mean ...

Exploring the power of Javascript for number lookup

I am currently working on a coding project using TypeScript and JavaScript to locate a specific number provided by the user within a list. The goal is to display whether or not the number is present in the list when the 'search' button is pressed ...

Gradient in Half Circle With JavaScript

How can I achieve a gradient effect within a circle using the following initial code: HTML: <div class="progresss"> <div class="barOverflow"> <div class="bar"></div> </div> <span>10</span>% </d ...

To prevent flickering when using child flex elements, it's best to use position fixed along with a dynamically updated scrollbar position using Javascript

My navigation component includes a slim banner that should hide upon scroll and a main-nav bar that should stick to the top of the screen and shrink when it does so. I initially looked into using Intersection Observer based on a popular answer found here: ...

Generating a downloadable picture with jQuery freeze frame

If you're looking to add animation to a gif upon mouseover, the Freezeframe plugin created by Chris Antonellis is the perfect solution. Simply use the command below: < img src="image.gif" freezeframe /> For a live example, visit his website he ...

What's the strangest glitch in Chrome related to repainting?

I am currently facing an issue with a form that contains hidden errors. The CSS for this form, written in Stylus, is as follows: span.error display: none position: relative padding: .25em .5em width: 75% margin-top: 5px margin-bottom: 15px f ...