当前位置:网站首页>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;
}
效果图如下:
中间的内容区可以上下滑动,超出的部分自动裁剪了。
边栏推荐
- Stew in disorder
- . Net delay queue
- Explore mongodb - mongodb compass installation, configuration and usage introduction | mongodb GUI
- Audio and video technology development weekly | 252
- Laravel simply realizes Alibaba cloud storage + Baidu AI Cloud image review
- Redis: SDS source code analysis
- One question per day 540 A single element in an ordered array
- Web components series - detailed slides
- How was MP3 born?
- Digital recognition system based on OpenCV
猜你喜欢
Qt---error: ‘QObject‘ is an ambiguous base of ‘MyView‘
@EnableAspectAutoJAutoProxy_ Exposeproxy property
I let the database lock the table! Almost fired!
DIY a low-cost multi-functional dot matrix clock!
The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
Anta is actually a technology company? These operations fool netizens
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
MFC implementation of ACM basic questions encoded by the number of characters
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
What should ABAP do when it calls a third-party API and encounters garbled code?
随机推荐
Anta is actually a technology company? These operations fool netizens
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平
Understand the rate control mode rate control mode CBR, VBR, CRF (x264, x265, VPX)
What is torch NN?
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
如何为ONgDB核心项目源码做贡献
TypeError: not enough arguments for format string
Lv166 turned over
AutoCAD - set color
Unity prefab day04
Go deep into the details of deconstruction and assignment of several data types in JS
The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
Expression #1 of ORDER BY clause is not in SELECT list, references column ‘d.dept_ no‘ which is not i
Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
PR FAQ: how to set PR vertical screen sequence?
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
Market trend report, technical innovation and market forecast of tetrabromophthalate (pht4 diol) in China