logo

The next-generation blog, news, and article for you to start sharing your stories today!

How To Fixed Table Heading in CSS

Fixed Table th tag using css. 

Fixed the table heading in css is pretty simple. you dont need to use any kind of jquery or javascript plugin

Here is simple code snippet .

Just example you have a simple table like 

Name Age
Sammy 28
Jammy 29

 So when data has been increase in the table you want to able to see the heading of the data on the same page. 

Okay so overcome this issue just use the simple css psudo code.

.table th {
  position: -webkit-sticky; /* Safari */
  position: sticky;
  top: 0;
}

.parent_div {
   position: relative 
}

 One more important things. When we use position sticky of any element the parent element postion should be relative.

Thank you.

 

avatar

Vikram Parihar

An editor at Keyscript

Vikram Parihar is an senior software engineer. He is working since 2013 in web development technologies. He works in NodeJS, Angular, Vue, PHP, Laravel, Express JS and various popular technologies.