CSS3 实现表头固定滚动

核心思想

  1. 主要使用CSS 3的新特性
position: sticky;
  1. sticky 是 relative 和 fixed 两者的结合体, 通常用在内容滚动的时候,固定滚动的内容
  2. 通常搭配的css 样式
top: 0px;
z-index: 2;
position: sticky !important;
  1. top需要指定偏移量,保证固定位置,注意:top, bottom, right, left 至少要一个
  2. z-index ,当内容滚动时,保持固定内容在上一层
  3. !important 表示该样式的优先级较高,不可被覆盖

代码如下

thead {
	display: block;
	position: stricky !important;
	top: 0px;
	z-index: 2;
}

猜你喜欢

转载自blog.csdn.net/weixin_42290927/article/details/108225312