html - Flex 列子子溢出高度
问题描述
我有一个包含顶部标题、内容区域和页面容器的简单应用程序的框架,如下所示:
.container {
height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
background-color: red;
}
.appheader {
width: 100%;
background-color: #cdcdcd;
color: blue;
text-align: center;
}
.appcontent {
width: 100%;
height: 100%;
background-color: blue;
}
.appcontentheader {
width: 100%;
background-color: black;
color: white;
text-align: center;
padding: 10px;
}
.page {
display: flex;
flex-direction: column;
background-color: yellow;
margin: 0px 50px 0px 50px;
width: 100%;
height: 100%;
}
.pagetitle {
background-color: grey;
color: orange;
text-align: center;
}
.pagecontent {
padding: 20px;
background-color: grey;
color: orange;
}
<div class="container">
<div class="appheader">
<h2>
MY APPLICATION MENU</h2>
</div>
<div class="appcontent">
<div class="appcontentheader">
<h4>
Section Title
</h4>
</div>
<div class="page">
<div class="pagetitle">
<h1>
PAGE TITLE
</h1>
</div>
<div class="pagecontent">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
</div>
</div>
</div>
我希望整个内容都可以放在一个页面中,而无需水平或垂直滚动。
至于这个例子,我的appcontent
和page
都溢出了 x 和 y 轴(黄色和黑色区域都溢出了)。
似乎是我的级联宽度:100% 和高度:100% 定义的问题。
为什么会发生这种情况以及如何正确修复它(将整个内容保留在视图中而不滚动,不使用scroll-x/y: hidden
?
解决方案
您还需要将弹性框应用于其包装器中的页面内容:
.page{
display: flex;
flex-direction: column;
...
}
这将确保允许页面内容根据您的布局正确弯曲。
推荐阅读
- c++ - 如何将彩色图像转换为密度单色图像?
- c# - Identity Server 4 API 身份验证失败
- android-build - 将 Android 捆绑文件上传到 HockeyApp
- matlab - MATLAB 中的大矩阵
- swift - 如何快速获取重复出现的字符的索引
- android - BLE 设备断开连接,然后是两个相反的异常 BleAlreadyConnectedException vs BleDisconnectedException
- filter - 如何更改 Tableau 筛选器内容大小?
- docker - 在 docker-entrypoint 中读取 Docker 机密
- awk - 在 Windows 中使用 awk 计算文件夹中多个文本文件中唯一单词的数量
- powerbi - 如何计算过去六个月 DAX 中 customerID 的不同计数?我需要看看客户有没有交易