Table header to stay fixed at the top when user scrolls it out of view with jQuery

后端 未结 25 2691
悲&欢浪女
悲&欢浪女 2020-11-22 05:38

I am trying to design an HTML table where the header will stay at the top of the page when AND ONLY when the user scrolls it out of view. For example, the table may be 500

25条回答
  •  深忆病人
    2020-11-22 06:10

    I found a simple solution without using JQuery and using CSS only.

    You have to put the fixed contents inside 'th' tags and add the CSS

    table th {
        position:sticky;
        top:0;
        z-index:1;
        border-top:0;
        background: #ededed;
    }
       
    

    The position, z-index and top properties are enough. But you can apply the rest to give for a better view.

提交回复
热议问题