CSS布局:sticky定位
stick定位一如其名:它随“正常”文档流而动,直到规定位置,尔后“粘”在那里;或者,当它发现自己可以跟随“正常”文档流而脱离sticky位置时,就果断离开从而加入文档流。
代码与效果如下:
<div style="height: 200px; overflow:scroll;">
<p style="background-color:lightgrey; position:sticky; top: 0px;">This is header A</p>
<p>This is content A</p>
<p>This is content A</p>
<p>This is content A</p>
<p>This is content A</p> <p style="background-color:lightgrey; position:sticky; top: 0px;">This is header B</p>
<p>This is content B</p>
<p>This is content B</p>
<p>This is content B</p>
<p>This is content B</p> <p style="background-color:lightgrey; position:sticky; top: 0px;">This is header C</p>
<p>This is content C</p>
<p>This is content C</p>
<p>This is content C</p>
<p>This is content C</p> <p style="background-color:lightgrey; position:sticky; top: 0px;">This is header D</p>
<p>This is content D</p>
<p>This is content D</p>
<p>This is content D</p>
<p>This is content D</p> </div>
标题行设置了背景色。如果不设置背景色(背景透明),正常文档流的文字就会和标题行文字重叠在一起显示。
sticky定位的元素会遮住滚动而来的“正常”的文档流;后面的sticky元素会覆盖前面的sticky元素,就好像一层层的便利贴。
This is header A
This is content A
This is content A
This is content A
This is content A
This is header B
This is content B
This is content B
This is content B
This is content B
This is header C
This is content C
This is content C
This is content C
This is content C
This is header D
This is content D
This is content D
This is content D
This is content D
CSS布局:sticky定位的更多相关文章
- CSS布局与定位——height百分比设置无效/背景色不显示
CSS布局与定位——height百分比设置无效/背景色不显示 html元素属性width和height的值有两种表达方式,一是固定像素如“100px”,一是百分比如“80%”, 使用百分比的好处是元素 ...
- 测开之路三十八:css布局之定位
常用的布局方式: static:静态定位(默认),什么都不用管,元素会按照默认顺序排列,排不下是会默认换行relative:相对定位(同一层),相对于某一个元素进行定位fixed:绝对定位,指定位置a ...
- Head First HTML与CSS — 布局与定位
1.流(flow)是浏览器在页面上摆放HTML元素所用的方法. 对于块元素,浏览器从上到下沿着元素流逐个显示所遇到的各个元素,会在每个块元素之间加一个换行: 对于内联元素,在水平方向会相互挨着,总体上 ...
- css 布局之定位 相对/绝对/成比例缩放
给body添加 overflow: hidden; 可以将页面所有的 滚动条隐藏,但必须要给body 设置一个高度 overflow: hidden; height:864px; 父元素必须要设置 p ...
- 前端学习笔记--CSS布局--float定位
1.float属性 box1向右移动,box2顶替了box1的位置,box3顶替了box2的位置. 2.clear属性 案例: 一列三行布局: <!DOCTYPE html> <ht ...
- 前端学习笔记--CSS布局--层定位
1.层定位概述: z-index:前后叠加顺序 2.position属性: 3.fixed: 2.relative: 移动后: static没有往上移动占据box1的位置. 3.absolute: 移 ...
- 深入css布局篇(2) — 定位与浮动
深入css布局(2) - 定位与浮动 在css知识体系中,除了css选择器,样式属性等基础知识外,css布局相关的知识才是css比较核心和重要的点.今天我们来深入学习一下css布局相关的知识 ...
- 【CSS】Sticky Footer 布局
什么是 Sticky Footer 布局? Sticky Footer 布局是一种将 footer 吸附在底部的CSS布局. footer 可以是任意的元素,该布局会形成一种当内容不足,footer ...
- 奇妙的CSS之布局与定位
前言 关于布局与定位是Web前端开发里非常基础而又重要的部分.介绍相关知识的文章,很容易就可以找到.虽然,这方面的知识点不是很多,但我们如果不弄清楚,在运用时候往往会出现预料之外的布局,这些“意外”有 ...
随机推荐
- Linux学习25-Xshell设置页面最大显示行数
前言 在使用xshell查看日志的时候,有时候日志太多,往上翻的时候,前面的就找不到了. 需要设置xshell的页面显示最大行数,查看更多的日志详情. 设置显示行数 左上角-文件-属性 终端-设置最大 ...
- JVM 性能调优工具
jdk自带的工具,在macOs系统中的目录位置(jdk具体版本位置要替换):/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Ho ...
- flutter 中的样式
flutter 中的样式 样式 值 width 320.0 height 240.0 color Colors.white,Colors.grey[300] textAlign TextAlign.c ...
- 导入Excel——解析Excel——优化
package com.it.excel.excelLearn; import java.io.FileInputStream; import java.io.IOException; import ...
- 2019年12月份关于Android Studio 需要了解的知识总结
因为期末项目答辩的原因,我和我的小组成员一起写了个作品展示app 就是用AndroidStudio写的 具体功能呢还加上了云服务器,bmob,等等 我是不知道那个云服务器要怎么配置啊,也不会用,都是 ...
- WHAT IS THE DIFFERENCE BETWEEN REACT.JS AND REACT NATIVE?
Amit Ashwini - 09 SEPTEMBER 2017 React.js was developed by Facebook to address its need for a dynami ...
- vmvare ESXi使用
新建主机,选择系统,自定义配置,选择ios镜像,完成,打开电源,开启配置
- 05-树9 Huffman Codes (30 分)
In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redunda ...
- python crawler
crawl blog website: www.apress.com # -*- coding: utf-8 -*- """ Created on Wed May 10 ...
- 如果用了flex去加一个箭头怎么让他剧中
左边是做了一个flex:1 右边是span的display:inline-block样式 父元素 .search-car-arrow display flex align-items center' ...