Sticky header table - Keep the content scrolling

Currently, I am in the process of creating a table with the help of the react-bootstrap library's Table component. You can find more information about this component by following this link.

<Table ordered hover>
    <thead>
        <tr>
            <th>Headers...</th> ...
        </tr>
    </thead>
    <tbody>
        <tr><td>Content here...</td></tr>
    </tbody>
</Table>

The main issue at hand is that this table contains a significant amount of data, prompting me to seek a solution where the content scrolls while keeping the header fixed at the top. To achieve this functionality, I have utilized specific CSS styles:

.container {
    height: 95vh;
}

table {
    overflow: scroll;
}

thead th { positon: sticky; top: 0px; }

After implementing these styles, upon scrolling, only the text within the header remains fixed at the top, causing an overlap between the header text and the data below it. This problem is illustrated in the screenshot linked below (observed on both Firefox and Chrome): https://i.sstatic.net/vsQ54.png

To address this issue effectively, how can I ensure that not only the header text but also its background remains sticky? This adjustment is crucial for enhancing readability within the table. Thank you for your assistance.

Answer №1

Perhaps position sticky is unnecessary in this case. Simply designate the tbody as the scrollable portion:

tbody {
  max-height: 95vh;
  overflow-y: scroll;
  display: block;
}

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

Unable to send email through Ajax/PHP contact form

It's quite amusing that it worked perfectly for one evening. After reaching out to my host, they assured me that there should be no issues with it not working. I even tried testing it in Firebug, but it appeared to be sending successfully. Additionall ...

What is the most effective method for integrating additional CSS/JS libraries into a GitHub repository?

I would like to integrate FontAwesome, Bulma, jquery, and jquery-ui into one of my Github repositories for the front-end section. Currently, I am including the JS files or CSS files from these projects in my own JS/CSS folders, but I believe there might ...

putting a division element above a image carousel

Is there a way to overlay a div tag on top of a slideshow, similar to the one shown in this link? In the example provided, a div with the title "DISCOVER THE JOY OF COOKING" is positioned over a slideshow. Any tips on how I can achieve this effect? ...

Problem encountered when trying to generate a custom-shaped div with a width set to 100

I am currently working on creating a diagonal div at the bottom of another div. I want it to have a design similar to this: . I encountered an issue when I tried adding a 100vw value to my border-left, as it caused a horizontal scrollbar to appear on my w ...

Modifying the appearance of scoped child components in Vue: A step-by-step guide

I am currently using vant ui components in my Vue project, such as buttons. I would like to make some minor style adjustments, like changing the color and border, but I am unsure how to do it. Can anybody please assist me in solving this issue? Thank you i ...

ColorBox fails to recognize the script running in the background

To display images, I am using a colorbox. Here is the code that calls the images: jQuery(".ImgPop").colorbox({ opacity: 0.4, rel: 'ImgPop', iframe: false, width: '770px', height: '680px', scalePhotos: ...

Issues arise with alignment of the button in an inline form when the Bootstrap navbar collapses

Currently delving into the world of Web Development and experimenting with BootStrap 4.0. I have a search field positioned to the right of the navbar, which looks fine in desktop view. However, as soon as the dimensions change to that of a phone, my nav li ...

How can I use CSS to center multiple divs with varying heights within a parent div?

Consider the HTML code provided below: <!DOCTYPE html> <html> <body> <div id="parent" style="border:1px solid #666;width:600px;height:200px;padding:5px;"> <div id="child1" style="border:1px solid #666;float:left;margin-left:10p ...

Risks associated with working with position:relative and left/top in web development

When using position: relative; with multiple elements, are there any potential issues to be aware of? Unlike position: absolute;, which may not display correctly on different monitors. For example: <img src="blah.png"/ class="someClass"> <im ...

Tips for extracting innerHTML or sub-string from all elements that have a specific class name using JavaScript

When it comes to shortening the innerHTML of an element by its Id, I have found success using either slice or substring. While I'm not entirely clear on the differences between the two methods, both accomplish what I need them to do. The code snippet ...

Switching the website address after picking an option from the drop-down menu

I have an HTML form that includes two dropdown menus. The first dropdown is populated from a database using PHP, and the second dropdown is linked to the first one and uses AJAX to update its values based on the selection from the first dropdown. My goal ...

What is the method for displaying specific text lines in italic format within the TextArea Tag in SAP Fiori Apps?

I need to format specific text lines in the "TextArea" tag of my SAP Fiori App in italic. The data for my text area is retrieved from a SAP OData Service as an Array. I am currently displaying the data using a loop and setting it as follows in my Java ...

Embed the Nest API into your HTML5 code

My mobile HTML5 application includes a script in the index.html file. Nest.js (code below) Whenever I run my application, I encounter an error stating that Firebase is not defined. This is odd because the function seems simple: --> var dataRef = new ...

What is the best way to position text at the bottom of an image using CSS?

Utilizing the jQuery Caption Plugin to showcase the image alt text when hovering over an image. Currently, the text is displaying at the top but I would like it to show at the bottom. Any suggestions on how to remedy this? Desired Outcome: Check out the ...

Improving CSS performance in React Styled Components

Which method is more efficient and why? I have heard that the css method in Styled-components can be resource-intensive. I am curious to know if using multiple nested ${(prop) => {}} functions is more costly compared to a single function with the css m ...

Conceal the Ajax Div and display the Loader Div while waiting for the data to be

Trying to show a loader div until the Ajax-populated div is returned. Want to hide "responseDiv" until it's filled with Ajax data and display a loading div in the meantime. #loading { background: url('images/loading.gif') no-repeat cent ...

Cannot populate Kendo Menu with images due to dataSource imageUrl not recognizing the content

I have integrated Kendo controls into my application, specifically a Menu control with a datasource in my controller. Currently, I am passing the relative path of URL for imageUrl. However, as the application has grown, there are multiple calls being made ...

Is there a way to identify the breakpoints of a header that has a changing number of menus?

I am currently designing a customizable header for a web application, where the admin has the ability to add or remove menus as desired. For instance: https://i.sstatic.net/37IeG.png Or https://i.sstatic.net/zbIPd.png The breakpoints for these two navigat ...

Use Ionic to inspect a specific value within a JSON array and then add a CSS class accordingly

I've been delving into the world of the ionic framework, working on a simple app to showcase some json data. I managed to style text strings in my ionic list with no issues (story.user), but now I want to change the background color based on different ...

What is the best way to position the <h:panelGrid> itself at a location other than the center?

Whenever I utilize this code snippet <h:panelGrid id="myGrid" columns="1" rendered="#{myBean.showResults}" width="50%" border="1" style="text-align: center;"> The panelGrid items will be centered HOWEVER, I desire to center the h:panelGrid it ...