Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use grid layout to make a table with frozen/fixed header

The fact that grid layout allows me to build a table in CSS in a completely different way, I was trying to figure out a way to make a grid layout where the first row stays in view, whilst the rest scroll. Importantly without losing the grid behavior (a 'cell' with a lot of content should change the width and/or height of the entire column and/or row including the unscrollable first row).

Is this possible?

like image 391
user2908232 Avatar asked Nov 02 '17 10:11

user2908232


People also ask

How do I make my table header fixed while scrolling?

By setting postion: sticky and top: 0, we can create a fixed header on a scroll in HTML tables.

How do I fix the header grid?

header {position:fixed; height: 80px; z-index: 10;} a grid definition within . wrapper will flow beneath the fixed header. For good measure, place the ruleset for . header at the top, before .

Is nesting grid possible with grid layout?

You can "nest" grids by making a grid item a grid container. These grids however are independent of the parent grid and of each other, meaning that they do not take their track sizing from the parent grid. This makes it difficult to line nested grid items up with the main grid.


1 Answers

I recently came upon this codepen from @Nicolas CHEVOBBE:

https://codepen.io/nchevobbe/pen/bYZEqq?editors=0110

It shows an example of what you describe. Fixed header row using grid layout. It's quite simple for a feature that takes a lot of effort to code otherwise.

The essential part is using position sticky on header cells:

[role=columnheader] {
  background-color: #F9F9FA;
  position: sticky;
  top: 0;
  padding: 5px;
  border-bottom: 1px solid #E3E4E4;
}

Hope it helps.

like image 90
Jonathan Urzúa Avatar answered Nov 15 '22 21:11

Jonathan Urzúa