当前位置:网站首页>overflow:auto与felx结合的用法
overflow:auto与felx结合的用法
2022-07-04 14:57:00 【大象与小蚂蚁】
overflow:auto;如果内容被修剪,则浏览器会显示滚动条,以便查看其余内容。
flex中的属性
display: flex;
flex-direction: column; 主轴为垂直方向,起点在上沿。
1、overflow和flex布局搭配使用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>overflow:auto的用法</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<style type="text/css">
html,body{
width: 100%;
height: 100%;
}
.container{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
.header{
width: 100%;
height: 100px;
background: #f99;
}
.content{
width: 100%;
height: 100%;
overflow: auto;
background: yellow;
flex: 1;
}
.footer{
width: 100%;
height: 100px;
background: #99f;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
</div>
<div class="content">
<ul>
<li>111111</li>
<li>111111</li>
<li>111111</li>
<li>111111</li>
<li>111111</li>
<li>111111</li>
<li>111111</li>
<li>111111</li>
这里的li要多写一些,这样才会显示效果,我这里为了省篇幅。
</ul>
</div>
<div class="footer">
</div>
</div>
</body>
</html>
要实现overflow: auto;这个效果,首先布局,再写样式。
在样式中要在最外边的父盒子container,加入以下样式:
.container{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
还有就是一定要给html和body给宽度和高度100%;
html,body{
width: 100%;
height: 100%;
}
头部和底部都给固定的高度,一般的app的头部和底部都是固定的,像微信聊天记录。
.header{
width: 100%;
height: 100px;
background: #f99;
}
.footer{
width: 100%;
height: 100px;
background: #99f;
}
中间的content给定flex:1,并且加上我们的主角overflow:auto;超出的内容自动裁剪。
.content{
width: 100%;
height: 100%;
overflow: auto;
background: yellow;
flex: 1;
}
效果图如下:
中间的内容区可以上下滑动,超出的部分自动裁剪了。
边栏推荐
- How was MP3 born?
- Actual combat | use composite material 3 in application
- The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
- Application of clock wheel in RPC
- Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
- MFC implementation of ACM basic questions encoded by the number of characters
- The four most common errors when using pytorch
- DIY a low-cost multi-functional dot matrix clock!
- Object distance measurement of stereo vision
- Stew in disorder
猜你喜欢
Will the memory of ParticleSystem be affected by maxparticles
Move, say goodbye to the past again
MFC implementation of ACM basic questions encoded by the number of characters
AI system content recommendation issue 24
Audio and video technology development weekly | 252
Communication mode based on stm32f1 single chip microcomputer
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
A trap used by combinelatest and a debouncetime based solution
What should ABAP do when it calls a third-party API and encounters garbled code?
How to decrypt worksheet protection password in Excel file
随机推荐
China's roof ladder market trend report, technological innovation and market forecast
Application of clock wheel in RPC
程序员怎么才能提高代码编写速度?
Accounting regulations and professional ethics [6]
Accounting regulations and professional ethics [10]
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
Practice: fabric user certificate revocation operation process
函數式接口,方法引用,Lambda實現的List集合排序小工具
C# 实现 FFT 正反变换 和 频域滤波
Software Engineer vs Hardware Engineer
Working group and domain analysis of Intranet
Market trend report, technical innovation and market forecast of China's hair repair therapeutic apparatus
What is torch NN?
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Research Report on market supply and demand and strategy of tetramethylpyrazine industry in China
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
L1-072 scratch lottery
Intranet penetrating FRP: hidden communication tunnel technology
Essential basic knowledge of digital image processing
时钟轮在 RPC 中的应用