Sticky table header with scrolling body

I am trying to display a scrollable table list with a fixed header, but I'm having issues with the header content not displaying properly without word wrapping. Additionally, there seems to be a 1px gap above the sticky header when scrolling through the content.

Here is my code snippet:

div.list_wrapper {
  height: 250px;
  overflow: auto;
}

thead tr th {
  position: sticky;
  top: 0;
}
<div class="list_wrapper col-md-12">
  <div class="table_wrapper table-responsive">
    <table class="">
      <thead>
        <tr>
          <td colspan="3"></td>
          <td>A text to be always displayed here</td>
        </tr>
        <tr>
          <th>Date</th>
          <th>Name</th>
          <th>Status</th>
        </tr>
      </thead>
      <tbody>
        <tr *ngFor="let list of OfficersList">
          <td>{{ list.updated_at | date:'d-MM-yyyy' }}</td>
          <td>{{ list.name }}</td>
          <td>{{ list.status }}</td>
          <tr>
      </tbody>
    </table>
  </div>
</div>

https://i.sstatic.net/P9zjk.png

Answer №1

It seems that the code snippet you provided is not functioning according to your description. Can you specify which specific row you want to remain sticky?

To address the issue you are experiencing, you might consider using the following CSS:

table {
  border-collapse: collapse;
  border-spacing: 0;
}

Answer №2

Attempt to eliminate the gap between borders

table {
  border-collapse: collapse;
 }
thead tr th {
    background-color: #f2f2f2;
}

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

Strip away the HTML tags and remove any text formatting

How can I effectively remove HTML tags and replace newlines with spaces within text? The current pattern I am using is not ideal as it adds extra space between words. Any suggestions on how to improve this pattern? replace(/(&nbsp;|<([^>]+)> ...

What could the possible reason behind the malfunctioning of my prepared statements for the insert operation?

I recently discovered that using prepared statements is a more effective method than using deprecated ones. Despite my best efforts and online tutorials, I haven't had any luck getting this to work or finding the problem. That's why I'm her ...

Transitioning to mui5's sx prop instead of makeStyles is generating a typescript error - none of the overloads match this call when passing an object with

I encountered an issue while converting a component to mui 5. Here is the original code snippet: const useStyles = makeStyles({ imageContainer: { display: "flex", width: "65%", float: "left", marginRight ...

Learn how to divide a container div with multiple sub-divs into two columns using CSS

Are you up for a good challenge? In my MVC project, I have a dynamic list of divs that I want to split into two columns. The number of divs in the list is unknown. How would you go about achieving this task? EDIT: Just to clarify, when I say split, I&a ...

The error message "TypeError: The object prototype can only be an Object or null: undefined in Angular"

When trying to launch my web app using 'ng serve', I am encountering an error that I cannot seem to resolve. The error message is quite cryptic, and despite updating dependencies and searching through similar questions, I am still unable to pinpo ...

The responsiveness of the Bootstrap website is lacking

Viewing the site on mobile @media screen and (max-width: 600px) { .sidebar { width: 100% !important; height: auto !important; } } @ ...

Unlocking the power of HTML tags in Selenium WebDriver: accessing elements like a pro

I'm working with this HTML snippet. <span class="ng-binding" ng-bind="::result.display">All Sector ETFs</span> <span class="ng-binding" ng-bind="::result.display">China Macro Assets</span> <span class="ng-binding" ng-bind ...

Adjust the color of a label based on a set threshold in Chart.js

Can anyone help me with my Chart.js issue? Here is a link to the chart: https://i.sstatic.net/RL3w4.gif I am trying to change the color of the horizontal label when it falls between 70.00 - 73.99. Does anyone know if there's a specific option for th ...

What is the reason for HTML Entity not functioning in the input title for React?

Can someone explain why I am unable to use the HTML Entity &le; in the HTML input title attribute when using a JavaScript constant, but it works fine with a string? The HTML Entity &le; represents the ≤ symbol. To demonstrate this issue, please ...

The font implemented in Bootstrap does not appear to be adapting well to different

As I embark on the Bootstrap journey, I find that everything looks great on my desktop browser in terms of responsiveness. However, when I switch to my iPhone 6, it doesn't seem to display as expected... Provided below are a few screenshots: Desktop ...

Arrange two <p> elements in a horizontal alignment

How can I align two <p> elements on the same line? I am trying to align both <p> elements on the same line, one to the left and the other to the right. <p style="text-align:left">Copyright &copy; {$date_year} {$companyname}. All R ...

Retrieving HTML DOM elements using the file_get_contents function

When using file_get_contents to fetch HTML content from a website, I encountered a table within the HTML structure that I need to extract data from. Here is an example of how I retrieve the HTML data from a URL: $url = 'http://example.com'; $con ...

Troubleshooting problems with encoding in Python Selenium's get_attribute method

Currently, I am utilizing Selenium with Python to crawl the drop-down menu of this particular page. By employing the find_elements_by_css_selector function, I have successfully obtained all the data from the second drop-down menu. However, when attempting ...

How can you incorporate a module for typings without including it in the final webpack bundle?

As I venture into the realm of Webpack, I am faced with the challenge of transitioning from TypeScript 1.x to TypeScript 2. In my previous projects, I typically worked with TypeScript in one module using separate files, TSD for typings, and compiling throu ...

Optimizing Your Angular2 Bundle with Webpack: Best Practices for Minimizing Code Size

I have attempted to include the --optimize-minimize option in my webpack command (version 2.1.0-beta.27), but I am still receiving a bundle.js instead of a bundle.min.js: "build:production": "node_modules/.bin/del-cli public/js/app && node_module ...

Employing flexbox to allow columns to shrink only when their width exceeds half of the container's size

Can you take a look at my drawing? Here is the scenario I'm trying to achieve: (1) I have a flexbox with two columns. If one box is bigger than half the width and there is enough space for both boxes, they should remain unchanged (or stretch propor ...

Currency formatting in ionic2 is not working properly when tested on a

Formatting currency in Ionic2 framework can be done like this: {{finalPremium | currency : 'eur' : true :'.2-2' }}. Interestingly, this functionality only appears to function properly in the browser. When tested on an iPhone device, no ...

What causes the child positioning to break when a CSS-Filter is applied to the parent element?

One of my projects includes a title-screen "animation" where the title is initially centered on a fullscreen page and then shrinks and sticks to the top as you scroll down. I have provided a simplified working example below: $(window).scroll( () => ...

Binary stream (byte array) compatible video player for seamless playback

Is there a JavaScript/jQuery/HTML5 video player that can play a video without needing a physical file? I have a video file stored in a database (varbinary(MAX)) and I am looking for a player that can play the video using the byte array source. Has anyone ...

Activating the CSS :active selector for elements other than anchor tags

How can I activate the :active state for non-anchor elements using JavaScript (jQuery)? After reading through Section 5.11.3 of the W3C CSS2 specification in relation to the :hover pseudo selector in hopes of triggering the activation of an element, I stu ...