question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fixed table header broken when cells have "position: relative" content

See original GitHub issue

When cell content uses position: relative, its painted on top of the fixed header.

For example, when the sample table looks like this:

<virtual-scroller #scroll
      [items]="filteredList">
      <table>
		<thead #header>
			<th>Index</th>
			<th>Name</th>
			<th>Gender</th>
			<th>Age</th>
			<th>Address</th>
		</thead>
		<tbody #container>
			<tr *ngFor="let item of scroll.viewPortItems">
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.index}}</div></td>
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.name}}</div></td>
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.gender}}</div></td>
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.age}}</div></td>
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.address}}</div></td>
			</tr>
		  </tbody>
      </table>
    </virtual-scroller>

… then it’s rendered like:

image

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

3reactions
natelokerscommented, Dec 10, 2018

I’m still trying to validate this in other browsers, but it seems like swapping the thead and the tbody in the HTML fixes this issue.

<virtual-scroller #scroll
      [items]="filteredList">
      <table>
		<tbody #container>
			<tr *ngFor="let item of scroll.viewPortItems">
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.index}}</div></td>
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.name}}</div></td>
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.gender}}</div></td>
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.age}}</div></td>
			  <td><div style="position: relative; color: red; font-weight: bold">{{item.address}}</div></td>
			</tr>
		  </tbody>
                  <thead #header>
			<th>Index</th>
			<th>Name</th>
			<th>Gender</th>
			<th>Age</th>
			<th>Address</th>
		</thead>
      </table>
    </virtual-scroller>
0reactions
markhbrowncommented, Dec 14, 2020

The problem is still in version 4.0.3.

But does work with the suggestion by @natelokers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixed table header broken when cells have "position: relative" content
When cell content uses position: relative , its painted on top of the fixed header. For example, when the sample table looks like...
Read more >
css - HTML Table Header with Fixed Position and scroll able ...
This will work if you don't have an horizontal scroll. ... text-transform: capitalize; position: relative; padding: 10px 25px 10px 25px; ...
Read more >
Position Sticky and Table Headers | CSS-Tricks
The issue boils down to the fact that stickiness requires position: relative to work and that doesn't apply to <thead> and <tr> in...
Read more >
<table>: The Table element - HTML - MDN Web Docs - Mozilla
This attribute defines the space between the content of a cell and its border, displayed or not. If the cellpadding's length is defined...
Read more >
Fixed Table Headers - Adrian Roselli
The different z-index values help ensure your column headers sit in front of your row headers. Otherwise the visible row header will look...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found