Site icon Css3 Transition

Table with fixed header and sidebar

table with fixed header and sidebar

Hello friends, here I am going to share table with fixed header and sidebar. Idea to develop this solution comes in mind when I was working on web project where I need to fixed the header and sidebar for the table. I needed a way to create a solution or new layout of table where header is fixed and fixed flexible sidebar that can adjust its width according to content. Here in this post I will share how I have created this layout using little help of javascript and advance CSS properties.

There are few key features of layout we are going to create:
  1. Sticky Header
  2. Sticky Sidebar
  3. Scrollable table body both vertical and horizontal.
Let’s start the work:

First of all we will create our normal html table structure where we have header and table body section, code as follow.

Html:

It is normal table structure nothing special coding in it. Now we will right our css code to get its layout and as well as special edit for table by CSS coding to provide it fancy layout and desired seperate header and sidebar.

Css Code:

In this css code you can see I have taken first Element th and td in both thead and tbody in table. Make these element display: block; in place display:table-cell; and assigned a min-width:300px;. along with this apply display:block; css to thead and tbody section too so that we can apply scroll on that. rest is normal css to beautiy this table.

Javascript:

Here I am applying scroll to tbody by simple javascript code. It is very simple and easy to understand as we know table body can not be scroll without any special edit so I am taking help of javascript and css as show in this example.

Exit mobile version