我有一个带有两个子容器的伸缩框容器,在较小的屏幕上,右侧应在左侧下方折叠。但是,这仅在父容器宽度为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
答案 0 :(得分:0)
如果这些大小是固定的,请使用网格而不是使用flexbox。
.call-out-box{
/*other styles*/
display:grid;
grid-template-columns: 540px 445px;
grid-template-rows: 365px 445px;
}
只需删除嵌入式样式中的width和height属性即可。
答案 1 :(得分:0)
如果尺寸固定,则使用网格 也去here jsfiddle
.call-out-container {
width: 100%;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
flex-wrap: wrap;
margin-top: 200px;
}
.call-out-box {
color: #eee;
display:grid;
grid-template-columns: 540px 445px;
grid-template-rows: 365px 445px;
}
.call-out-list {
color: #eee;
font-weight: bold;
font-size: 3em;
text-align: center;
padding-top: 100px;
}
.call-out-list h1{
font-family: 'Helvetica';
color: #00477B;
font-weight: 400;
font-size: 56px;
}
.call-out-list 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>