使用flex固定头部和底部中间滚动
来源:互联网 发布:tomcat怎么改端口号 编辑:程序博客网 时间:2024/05/21 17:57
使用flex固定头部和底部中间滚动
关键点:
* root纵向布局高度充满整个浏览器界面并且隐藏滚动条
* content设置滚动,flex设置1,否则当所有item的高度太小时footer会离开底部
* item设置高度后,必须设置flexShrink为0,否则当所有item高度超过content高度时item会被压缩掉
‘100vh’浏览器视口高度的百分比,这里是100%;
flex为1其他元素为0时(默认为0),当有多余空间时会被flex为1的元素侵占;
flexShrink为0,当空间被压缩时flexShrink为0的元素不被压缩;
代码如下:
class App extends React.Component { render() { const items = [1, 2, 3, 4, 5, 6, 7] return ( <div style={Style.root}> <div style={Style.head}>head</div> <div style={Style.content}> {items.map((item, index) => { return <div key={index} style={Style.item}>{item}</div> })} </div> <div style={Style.footer}>footer</div> </div> ) }}const Style = {}Style.root = { display: 'flex', flexDirection: 'column', height: '100vh', overflowY: 'hidden'}Style.head = { height: 80, backgroundColor: '#ccc',}Style.footer = { height: 80, backgroundColor: '#ccc',} Style.content = { display: 'flex', flexDirection: 'column', flex: 1, overflowY: 'scroll'}Style.item = { display: 'flex', height: 200, flexShrink: 0, backgroundColor: 'rgb(232, 128, 36)', margin: 10}export default App;
阅读全文
0 0
- 使用flex固定头部和底部中间滚动
- 头部和底部固定,中间内容可滚动
- 手机html开发,简单实例,头部底部固定,中间可以滚动
- flex上下固定中间滚动布局
- 基于flex弹性布局头尾固定,中间滚动效果实现
- Phonegap+Android固定头部和底部工具栏的方法
- 表格固定头部,底部,左侧
- 顶部和底部固定中间自适应的布局
- CSS实现自适应高度布局:头部底部固定,中间自适应铺满屏幕剩余高度,中间盒子里左盒子固定右盒子自适应宽度
- android实现顶部底部标题栏固定 中间可滚动,仿QQ空间的主界面布局
- 上下固定,中间可滚动
- 头部底部固定的另一种实现方式
- 基于flex弹性布局实现“头尾固定,中间滚动”的页面(纯CSS实现)
- 基于flex弹性布局实现“头尾固定,中间滚动”的页面(纯CSS实现)
- 弹出输入法时,固定顶部。移动中间, SearchView 固定头部 editView 固定头部
- 使用css实现页面头部固定,下面随着内容的增多滚动,但是头部不动的效果
- RecyclerView添加头部和底部
- RecycleView添加头部和底部
- C语言的关键字,运算符,标识符
- 将以逗号分隔的id字符串按每20个id截取分组
- nodejs根据url下载图片存储到当前目录
- 冒泡法排序
- codeforces 449 D Jzzhu and Numbers(容斥+dp)
- 使用flex固定头部和底部中间滚动
- python中装饰器的理解
- HDU 6161 树形DP + 优化
- 输入地名获取相应的百度坐标
- MySQL——修改root密码的4种方法(以windows为例)
- react判断滚动到底部以及保持原来的滚动位置
- HTML canvas画布
- js库支持CommonJs和浏览器的标准写法
- Net面试题