Complete the table until it reaches the available space, making sure to maintain the header and footer

In my live page, I have a section that has limited space based on the viewport size.

The layout includes:

  1. Content above the table
  2. Table with Header and Body
  3. Content below the table

Currently, the section overflows due to having too many items in the table. I want to make it scrollable while keeping the content above at the top and the content below at the bottom of the available space.

I need the table body to occupy the available space, maintaining the placement of the content above and below.

How can I achieve this?

* {
color: #ffffff;
}

section 
{
  height: 200px;
}

section .table-wrapper {
  background-color: #202020;
  padding: 0;
}
...
...

To address this issue, I utilized CSS Grid and set appropriate sizes for each element, separating the three parts into multiple elements (the footer was included within an element along with the table). The remaining task is to resolve the table header alignment.

section .table-wrapper {
  //...
  display: grid;
  grid-template-rows: fit-content(100%) auto fit-content(100%);
  grid-template-areas: "header" "main" "footer";
}

section .row {
  //...
  flex-wrap: nowrap;
}

... ...

Answer №1

Simply relying on CSS and HTML won't cut it. JavaScript is essential to reach your desired outcome.

To be more precise, consider utilizing Intersection Observer. This tool allows you to alter CSS styles or add/remove classes from an element based on its visibility. For instance, you could trigger an action when a user scrolls past a certain point where the table header disappears. Alternatively, you could set conditions for when the table header is only visible at 50% or less. The possibilities are endless.

If you're unfamiliar with Intersection Observer, watching tutorials on YouTube can provide a good starting point to grasp its functionality.

Another approach is to manually calculate everything. In this scenario, you would need to determine the specific scroll distance (in pixels) required to take the desired action. Here's a basic example of how the code might look:

if(window.pageYOffset > 150) {
   // implement CSS changes here
}

Check out this simple demonstration using this method

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

Retrieve the toggle input value to change the page view using jQuery

I'm currently working on a web photo gallery project and I am looking to incorporate a toggle input button that allows users to switch between displaying albums or all photos. To achieve this, I need to extract the value of the input using jQuery and ...

Problem with Agile Carousel and thumbnail component

I have incorporated the Agile Carousel plugin into my website to create multiple slideshows. The first slideshow at the top is working fine, but I am experiencing an issue with the carousel in the "About" section at the bottom. While I have successfully se ...

Arranging a Vertical Element Within a Rotated Holder

Who would have thought that geometry would come into play when working with CSS? I need help figuring out how to perfectly cover a rotated container with an upright background image. The goal is to hide the rotation on the sides and maintain dynamic contro ...

"What is the best way to switch between multiple data targets and toggles in bootstrap using the HTML data toggle attribute

I am currently coding an animated hamburger icon for the Bootstrap navbar, and I need to find a way to toggle both the hamburger icon and the responsive navbar. Is there a method or code snippet that allows me to toggle these two elements independently usi ...

I am having trouble getting my tag to function properly within the if statement of my template

My goal is to show a notification badge in my inbox only if there are more than 0 messages. However, I'm facing an issue with my if statement. I'm uncertain whether it's a syntax problem or a logic error. The message count is correctly displ ...

Adjustable design and content containment

Currently, I am exploring ways to utilize CSS in order to control the layout of my website effectively. My goal is to have the main frame of the website contain and confine all content within it. However, since I have not written any code yet, allow me to ...

Using a comma as a decimal separator for input is not permitted when working with angular/typescript/html

I am facing an issue with my Angular frontend where I have numerous html input fields that trigger calculations upon typing. <input type="text" [(ngModel)]="myModel.myAttribute" (input)="calculate()"> The problem arise ...

Obtaining the actual dimensions of an image

I am trying to retrieve the original height and width of an image stored in a variable called var IMG = $("img"). The code I have written functions correctly except when used on Win XP IE8. Can someone help me troubleshoot this issue? $("<img/>") ...

Add a border to the navigation bar item to indicate the current page being displayed

This section shows the current navigation bar item https://i.sstatic.net/6RAGJ.png This is the desired outcome when clicking on the tab https://i.sstatic.net/8nFeB.png Uncertain about the best approach for achieving this. I have attempted to submit a val ...

Issue with fading hover effect on links is not functioning

I recently implemented a fade link hover effect using the code snippet below: a:link {color:#333333; text-decoration: none; -o-transition:.5s; -ms-transition:.5s; -moz-transition:.5s; -webkit-transition:.5s; transition:.5s;} a:visited {color:#FF0033; ...

Highlight the active page or section dynamically using HTML and jQuery - How can it be achieved?

What am I trying to achieve? I am attempting to use jQuery to dynamically highlight the current page from the navigation bar. Am I new to jQuery/HTML? Yes, please excuse my lack of experience in this area. Have I exhausted all resources looking for a sol ...

Guide for positioning the p-checkbox label to the left of the checkbox using PrimeNG

<p-checkbox name="group1" [value]="true" label="Outsourcing" style="margin: 0 25px"></p-checkbox> I am looking to change the position of the label from the right to the left ...

Guide to using two UI grids simultaneously with the directives ng-hide and ng-grid

As a newcomer to AngularJS, I am attempting to create a page with two ui-grid elements and a button labeled "other-grid". The goal is for the first grid to load initially, and when clicked again, it should be replaced by the second grid. However, I am en ...

Issue with the Animated Skill Bar not functioning properly when scrolling

I've been trying to implement an animated skill bar in my Portfolio using JQuery, but I'm facing some challenges. Despite following various tutorials, the code doesn't seem to work as expected. I've tried calculating section scroll posi ...

Utilize PHP to conduct a Json comparison and perform an insertion

Since receiving assistance from @rx2347, everything is functioning correctly except for one issue. I have revised my question to provide a clearer explanation of the problem. I have a JSON array from which I am extracting specific data such as 'id&ap ...

"Enhance Your Website with Custom CSS Backgrounds

Can anyone provide information on the popular CSS style currently seen in many websites? This style features a full-screen background with the website's content displayed on top under smaller dimensions. An example of this can be seen on a website li ...

divs aligned vertically on opposite edges of the webpage

Our web app is being embedded in a third party page as an iframe, but we need to add a bottom "toolbar" with 2 links. One link should be plain text and the other should display our company logo preceded by some text. We want the two links to be positioned ...

Equal widths that adapt and respond to different screen sizes

Currently, I am in the process of transforming a 960grid 12col responsive design into HTML. There are three separate div elements, each with a width of 300px and a margin-right of 20px. Below is the code snippet that illustrates this: HTML <section cl ...

Adjusting the size of MaterialUI SVG icon: a simple guide

Hey everyone, I'm having some trouble trying to make this MaterialUI icon larger. I've attempted changes with the viewbox and inline styling, but no luck so far. The current size of the icon isn't cutting it for me, I need it to be bigger. ...

Capture information from an HTML5 form and securely store it in a MySQL database

I have a simple web form that includes a "date" type input field. I want to retrieve the date entered by the user and store it in my MySQL database, which has a DATE type column. I am looking for some PHP/JS magic to facilitate the communication between t ...