当前位置:网站首页>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;
}
效果图如下:
中间的内容区可以上下滑动,超出的部分自动裁剪了。
边栏推荐
- MySQL - MySQL adds self incrementing IDs to existing data tables
- AutoCAD - set color
- Penetration test --- database security: detailed explanation of SQL injection into database principle
- Research Report on surgical otorhinolaryngology equipment industry - market status analysis and development prospect prediction
- 时钟轮在 RPC 中的应用
- Explore mongodb - mongodb compass installation, configuration and usage introduction | mongodb GUI
- [North Asia data recovery] a database data recovery case where the disk on which the database is located is unrecognized due to the RAID disk failure of HP DL380 server
- Summary of database 2
- Review of Weibo hot search in 2021 and analysis of hot search in the beginning of the year
- Practice: fabric user certificate revocation operation process
猜你喜欢

Scientific research cartoon | what else to do after connecting with the subjects?

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)

~88 running people practice

Model fusion -- stacking principle and Implementation

QT graphical view frame: element movement

Cut! 39 year old Ali P9, saved 150million
![[native JS] optimized text rotation effect](/img/50/3c09f223e821c14e7e9e0fb47622b6.jpg)
[native JS] optimized text rotation effect

@EnableAspectAutoJAutoProxy_ Exposeproxy property
![[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded](/img/c5/f933ad4a7bc903f15beede62c6d86f.jpg)
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
随机推荐
Unity prefab day04
China Indonesia adhesive market trend report, technological innovation and market forecast
c# 实现定义一套中间SQL可以跨库执行的SQL语句
Logstash ~ detailed explanation of logstash configuration (logstash.yml)
[book club issue 13] ffmpeg common methods for viewing media information and processing audio and video files
165 webmaster online toolbox website source code / hare online tool system v2.2.7 Chinese version
Research Report on market supply and demand and strategy of China's four sided flat bag industry
JS to realize the countdown function
Socks agent tools earthworm, ssoks
Find numbers
Understand the rate control mode rate control mode CBR, VBR, CRF (x264, x265, VPX)
Understand asp Net core - Authentication Based on jwtbearer
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
Penetration test --- database security: detailed explanation of SQL injection into database principle
Proxifier global agent software, which provides cross platform port forwarding and agent functions
Selenium browser (2)
Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
Market trend report, technical innovation and market forecast of electrochromic glass and devices in China and Indonesia
Research Report on market supply and demand and strategy of surgical stapler industry in China
China's plastic processing machinery market trend report, technological innovation and market forecast