当前位置:网站首页>元素使用 align-items center 和 overflow auto 之后,部分内容显示不全
元素使用 align-items center 和 overflow auto 之后,部分内容显示不全
2022-06-30 00:30:00 【Zheng One Dream】
当我们为了让内容居中使用了 align-items center 属性之后,因为屏幕小的会遮挡一部分内容
我们就会给盒子再加上 overflow-y auto 这个属性
但是当我们缩小屏幕时,会发现,内容的上半部分会显示不出来
<style>
.box {
height: 100vh;
display: flex;
align-items: center;
overflow-y: auto;
}
.content {
height: 600px;
}
</style>
<body>
<div class="box">
<div class="content"></div>
</div>
</body>这是因为元素在侧轴居中。如果元素在侧轴上的高度高于其容器,那么在两个方向上溢出距离相同
参考文档:
align-items - CSS(层叠样式表) | MDN
这里提供两种解决方案:
1. 嵌套一层盒子
<style>
.container {
height: 100vh;
display: flex;
align-items: center;
overflow-y: auto;
}
.box {
height: 100%;
}
.content {
height: 600px;
}
</style>
<body>
<div class="container">
<div class="box">
<div class="content"></div>
</div>
</div>
</body>2. 将 display flex 改为 display grid
<style>
.box {
height: 100vh;
display: grid;
align-items: center;
overflow-y: auto;
}
.content {
height: 600px;
}
</style>
<body>
<div class="box">
<div class="content"></div>
</div>
</body>======================这里写一些废话,不用看
因为 csdn 假装自己很了解文章质量
你写的少就是质量差的文章,它不会往上给你推,就很搞笑
csdn 新加的质量检测功能,真的6,“ yyds ”
我相信遇到这个问题,我的答案可以解决 100% 的问题,你说我的文章质量不够?
难道要让我写很多废话在文章里吗?
边栏推荐
- Is there any discount for securities account opening? Is it safe to open an account online?
- 科创人·味多美CIO胡博:数字化是不流血的革命,正确答案藏在业务的田间地头
- Quick Pow: 如何快速求幂
- DataGridView上移 下移行
- 固定资产管理系统多少钱,固定资产管理系统价格
- TwinCAT 3 EL7211模块控制倍福伺服
- 股票网上开户及开户流程怎样?还有,在线开户安全么?
- Solr basic operation 11
- MySQL Foundation 2
- 炒股开户选择哪家证券公司比较好哪家平台更安全
猜你喜欢

【每日一题】二叉树的前后序遍历
![[QNX Hypervisor 2.2用户手册]6.2.2 Guest与Host之间通信](/img/a4/a84f916d3aa2cc59f5b686cd32797a.png)
[QNX Hypervisor 2.2用户手册]6.2.2 Guest与Host之间通信
![[advanced C language] user defined type](/img/0d/50924ef21f07ca8188855c2b78d929.png)
[advanced C language] user defined type

Le module twincat 3 el7211 contrôle les servocommandes baffle

初始I/O及其基本操作

Can't recognize the original appearance

Sword finger offer II 035 Minimum time difference

Which direction of network development is better? Data communication engineer learning path sharing

关联性——典型相关分析
![[dynamic programming] - linear DP](/img/cb/4ad8dce1da1d1110d6e79fadca4293.png)
[dynamic programming] - linear DP
随机推荐
Stack space of JVM
C语言课设心得之“推箱子”课设作品开源分享
固定资产管理系统多少钱,固定资产管理系统价格
Solr basic operation 11
Five key elements of the data center
云呐|固定资产系统管理的优势,固定资产管理系统有何特点
学位论文的引用
DataGridView上移 下移行
vim插件管理器vim-plug安装方法
Stream collectors usage
分布式任务调度 ElasticJob demo
《性能之巅第2版》阅读笔记(四)--Memory监测
SSH key disclosure (module B competition topic) -- Application Service Vulnerability scanning and utilization
【服装软件】服装出产办理体系选型的准则有哪些?
IO stream summary
leetcode 416. Partition Equal Subset Sum 分割等和子集(中等)
[daily question 1] traversal of binary tree
[advanced C language] dynamic memory management
Can't recognize the original appearance
MySQL primary key constraint deletion