gpt4 book ai didi

css - Flex wrap 不适用于固定宽度的容器

转载 作者:行者123 更新时间:2023-11-28 01:13:04 25 4
gpt4 key购买 nike

我有一个带有两个子容器的 flex-box 容器,在较小的屏幕上,右边的应该折叠在左边的下面。但是,这似乎只在父容器宽度为 100% 时有效,而在设置为固定宽度时无效。它需要基于设计的固定宽度,我尝试将固定宽度的容器包装在宽度为 100% 的父容器中,但这没有效果。

如何将容器设置为固定宽度,以便元素在较小的屏幕尺寸下正确包装?

.call-out-container {
width: 1172px;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
flex-wrap: wrap;
}

.call-out-box {
color: #eee;
font-weight: bold;
font-size: 3em;
text-align: center;
}

.call-out-box {
width: auto;
height: 200px;
color: #eee;
font-weight: bold;
font-size: 3em;
text-align: center;
}

.call-out-box h1 {
font-family: 'Helvetica';
color: #00477B;
font-weight: 400;
font-size: 56px;
}

.call-out-box p {
color: #333;
font-size: 12px;
}
    <div class="call-out-container">
<div class="call-out-box">
<div style="width: 540px; height: 365px; margin: 0px 0px 0px 80px; display: flex; border: 2px solid orange; justify-content: center;">
<div style="width: 445px; height: 445px; background-color: rgb(255, 255, 255); box-shadow: rgb(221, 221, 221) 0px 3px 11px 4px; position: relative; right: -30px; top: 20px; text-align: center; vertical-align: middle;">
<p>CONTENT</p>
</div>
</div>
</div>
<div class="call-out-list">
<h1>10.5k</h1>
<p>Line 1</p>
<p>Line 2</p>
</div>
</div>


<div class="call-out-container">
<div class="call-out-list">
<h1>10.5k</h1>
<p>Line 1</p>
<p>Line 2</p>
</div>
<div class="call-out-box">
<div style="width: 540px; height: 365px; margin: 0px 0px 0px 80px; display: flex; border: 2px solid orange; justify-content: center;">
<div style="width: 445px; height: 445px; background-color: rgb(255, 255, 255); box-shadow: rgb(221, 221, 221) 0px 3px 11px 4px; position: relative; right: -30px; top: 20px; text-align: center; vertical-align: middle;">
<p>CONTENT</p>
</div>
</div>
</div>
</div>

JSFIDDLE 链接:LINK

最佳答案

如果这些尺寸是固定的,请使用网格而不是使用 flexbox。

.call-out-box{
/*other styles*/
display:grid;
grid-template-columns: 540px 445px;
grid-template-rows: 365px 445px;
}

只需删除行内样式中的宽度和高度属性即可。

关于css - Flex wrap 不适用于固定宽度的容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52008114/

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