gpt4 book ai didi

html - 3 列 flexbox 在某些小型设备上无法正确堆叠

转载 作者:太空宇宙 更新时间:2023-11-04 09:11:19 24 4
gpt4 key购买 nike

首先,我是一名业余爱好者-希望您能原谅!我正在尝试实现一个 3 列 flexbox 布局(我只为等高 div 选择它),它会自动堆叠在小型设备上。我已经尝试了所有我能想到的方法,但结果是前两个 div 列保持在同一行,而第三个 div 列换行到下一行。我在 CSS 中添加了第四个 child ,因为我最初想要 4 列,但删除它对我遇到的问题没有任何影响。我已经阅读了大量内容,但似乎找不到答案。也许有人有类似的问题?

这是 CSS:

.flexbox {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
align-items: stretch;

}


.flexbox .col {
flex: 1;
margin: 10px;
}

.flexbox .coltext {
flex: 1;
padding: 15px;
margin: 10px;
background: #fff;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);

}
.flexbox .col:nth-child(1) {
background: #fff;
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}
.flexbox .col:nth-child(2) {
background: #fff;
-webkit-order: 1;
-ms-flex-order: 1;
order: 1;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}
.flexbox .col:nth-child(3) {
background: #fff;
-webkit-order: 2;
-ms-flex-order: 2;
order: 2;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}

.flexbox .col:nth-child(4) {
background: #fff;
-webkit-order: 3;
-ms-flex-order: 3;
order: 3;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}


@media (max-width: 480px) {
#container div {
max-width: 98%;
}
}
@media (min-width: 480px) and (max-width: 1080px) {
#container div {
max-width: 48%;
}
}
@media (min-width: 1080px) {
#container div {
max-width: 23%;
}
}

这是 html(删除了描述性文本):

<div class="flexbox">
<div class="col">
<img src="images/homepage_images/OVERHEAD (4).jpg" style="width:100%"><br><br>
<h5><center><strong>Bournemouth Town Centre regeneration</strong></center></h5>
<p class="justify text-justify w3-padding">
<br><br>
<a class="w3-btn w3-red w3-medium" href="#">learn more..</a></p>
</div>


<div class="col">
<img src="images/homepage_images/Poundstock.jpg" style="width:100%"><br><br>
<h5><center><strong>contract awards</strong></center></h5>
<p class="justify text-justify w3-padding"> <br><br>
<a class="w3-btn w3-red w3-medium" href="#">learn more..</a></p>
</div>



<div class="col">
<img src="images/homepage_images/_MG_0342rawprepx.jpg" style="width:100%"><br><br>
<h5><center><strong>latest from General Works</strong></center></h5>
<p class="justify text-justify w3-padding">
<br><br> <a class="w3-btn w3-red w3-medium" href="#">view</a></p></div>
</div>

最佳答案

达到预期效果的一种简单方法是将 flex-direction 设置为 column :

@media (max-width: 480px) {
#container div {
max-width: 98%;
}
.flexbox {
flex-direction: column;
}
}

SNIPPET(缩小输出窗口)

.flexbox {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
align-items: stretch;

}


.flexbox .col {
flex: 1;
margin: 10px;
}

.flexbox .coltext {
flex: 1;
padding: 15px;
margin: 10px;
background: #fff;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);

}
.flexbox .col:nth-child(1) {
background: #fff;
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}
.flexbox .col:nth-child(2) {
background: #fff;
-webkit-order: 1;
-ms-flex-order: 1;
order: 1;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}
.flexbox .col:nth-child(3) {
background: #fff;
-webkit-order: 2;
-ms-flex-order: 2;
order: 2;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}

.flexbox .col:nth-child(4) {
background: #fff;
-webkit-order: 3;
-ms-flex-order: 3;
order: 3;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}


@media (max-width: 480px) {
#container div {
max-width: 98%;
}
.flexbox {
flex-direction: column;
}
}
@media (min-width: 480px) and (max-width: 1080px) {
#container div {
max-width: 48%;
}
}
@media (min-width: 1080px) {
#container div {
max-width: 23%;
}
}
<div class="flexbox">
<div class="col">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" style="width:100%"><br><br>
<h5><center><strong>Bournemouth Town Centre regeneration</strong></center></h5>
<p class="justify text-justify w3-padding">
<br><br>
<a class="w3-btn w3-red w3-medium" href="#">learn more..</a></p>
</div>


<div class="col">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" style="width:100%"><br><br>
<h5><center><strong>contract awards</strong></center></h5>
<p class="justify text-justify w3-padding"> <br><br>
<a class="w3-btn w3-red w3-medium" href="#">learn more..</a></p>
</div>



<div class="col">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" style="width:100%"><br><br>
<h5><center><strong>latest from General Works</strong></center></h5>
<p class="justify text-justify w3-padding">
<br><br> <a class="w3-btn w3-red w3-medium" href="#">view</a></p></div>
</div>

关于html - 3 列 flexbox 在某些小型设备上无法正确堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42100369/

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