gpt4 book ai didi

css - 垂直调整窗口大小时 Div 容器消失

转载 作者:行者123 更新时间:2023-11-28 11:57:05 24 4
gpt4 key购买 nike

我有一个奇怪的问题,为什么当我垂直调整窗口大小时,我的 div 容器缩小/消失并且不遵循正常的网站布局。这是我正在谈论的内容的屏幕截图。

enter image description here

如您所见,红色应该覆盖了所有内容,包括包含所有颜色的框。只有当我垂直调整网页大小时才会出现这种情况,我不明白为什么会这样。

这是我的代码:

.main-content {
display: flex;
flex-direction: column;
height: calc(100% - 84px);
}

.main-content-container {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
background: red;
}

.info-box-container {
display: flex;
justify-content: center;
}

.info-box {
display: flex;
height: 195px;
width: 350px;
background: white;
margin-right: 15px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
}

.info-box .left-side {
display: flex;
flex-direction: column;
flex: 1;
background: red;
}

.info-box .top {
flex: 1;
display: flex;
justify-content: center;
background: yellow;
}

.info-box .top p {
margin-bottom: 5px;
background: green;
font-size: 25px;
align-self: flex-end;
}

.info-box .bottom {
flex: 1;
display: flex;
justify-content: center;
background: orange;
}

.info-box .right-side {
flex: 1;
background: blue;
}

.info-box:last-child {
margin: 0;
}

.welcome-msg {
text-align: center;
height: auto;
}

.welcome-msg p {
font-size: 30px;
font-weight: lighter;
}
<div class="main-content">
<div class="main-content-container">
<div class="welcome-msg">
<p>Welcome, Omar</p>
</div>
<div class="info-box-container">
<div class="info-box">
<div class="left-side">
<div class="top">
<p>500</p>
</div>
<div class="bottom">
<p>Reports</p>
</div>
</div>
<div class="right-side">

</div>
</div>
</div>
</div>
</div>

谢谢!

最佳答案

您可以将 min-height 添加到 .main-content。在您的情况下,.info-box 的高度为 195px。将 .main-contentmin-height 设置为 195px,这样当您调整屏幕大小时它不会缩小超过 195px ,即 .info-box 的大小。

https://codepen.io/samuellawrentz/pen/wxKRga

.main-content {
display: flex;
flex-direction: column;
height: calc(100% - 84px);
min-height: 195px;
}

.main-content-container {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
background: red;
}

.info-box-container {
display: flex;
justify-content: center;
}

.info-box {
display: flex;
height: 195px;
width: 350px;
background: white;
margin-right: 15px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
}

.info-box .left-side {
display: flex;
flex-direction: column;
flex: 1;
background: red;
}

.info-box .top {
flex: 1;
display: flex;
justify-content: center;
background: yellow;
}

.info-box .top p {
margin-bottom: 5px;
background: green;
font-size: 25px;
align-self: flex-end;
}

.info-box .bottom {
flex: 1;
display: flex;
justify-content: center;
background: orange;
}

.info-box .right-side {
flex: 1;
background: blue;
}

.info-box:last-child {
margin: 0;
}

.welcome-msg {
text-align: center;
height: auto;
}

.welcome-msg p {
font-size: 30px;
font-weight: lighter;
}
<div class="main-content">
<div class="main-content-container">
<div class="welcome-msg">
<p>Welcome, Omar</p>
</div>
<div class="info-box-container">
<div class="info-box">
<div class="left-side">
<div class="top">
<p>500</p>
</div>
<div class="bottom">
<p>Reports</p>
</div>
</div>
<div class="right-side">

</div>
</div>
</div>
</div>
</div>

关于css - 垂直调整窗口大小时 Div 容器消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51334996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com