gpt4 book ai didi

html - 调整浏览器大小时对齐 Flexbox 部分

转载 作者:可可西里 更新时间:2023-11-01 13:50:25 25 4
gpt4 key购买 nike

enter image description here

上面是它在 1920 宽度浏览器上的外观截图。这基本上是我想要的布局,但是当我调整浏览器大小时,它看起来像这样: enter image description here

我希望这些框在各个部分的左右两侧没有白色间距,并在有/没有间距的情况下使它们保持相同的 100% 宽度

我意识到间距的出现是因为代码是如何设置的,其中中间部分有将它推开的边距,但我不确定如何设置它以实现第一个屏幕截图和这种效果。

fiddle :https://jsfiddle.net/jzhang172/r641pmzb/

body,
html {
margin: 0px;
font-family: lato-reg;
font-size: 16px;
color: #3c3c3c;
overflow-x: hidden;
}
img {
width: 100%;
height: 100%;
}
.section {
position: relative;
}
/*--------------------------------------Fifth Section--*/

.flex-container {
margin-top: 10px;
width: 100%;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-flex-flow: row wrap;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
}
.work-indiv {
width: 540px;
-webkit-flex: auto;
-ms-flex: auto;
flex: auto;
display: inline-block;
height: 237px;
position: relative;
margin-bottom: 10px;
cursor: pointer;
transition: 1s;
}
.work-indiv:hover img {
opacity: .6;
transition: .6s;
}
.middle {
padding-left: 10px;
padding-right: 10px;
width: 783px;
}
.work-indiv span {
position: absolute;
clear: both;
bottom: 0;
left: 0;
color: White;
margin-left: 40px;
text-transform: uppercase;
margin-bottom: 40px;
font-size: 2.125em;
font-family: latobold;
letter-spacing: .16em;
}
.middle span {
margin-left: 50px;
}
<div class="section" id="fifth">
<div class="flex-container">
<div class="work-indiv">
<img src="https://pixabay.com/static/uploads/photo/2015/12/21/06/41/landscape-1102117_960_720.jpg" alt="Topworkz">
<span>Topworkz</span>
</div>
<div class="work-indiv middle">
<img src="https://pixabay.com/static/uploads/photo/2015/12/21/06/41/landscape-1102117_960_720.jpg" alt="Joint">
<span>Joint</span>
</div>
<div class="work-indiv">
<img src="https://pixabay.com/static/uploads/photo/2015/12/21/06/41/landscape-1102117_960_720.jpg" alt="Market">
<span>Market</span>
</div>

<div class="work-indiv">
<img src="https://pixabay.com/static/uploads/photo/2015/12/21/06/41/landscape-1102117_960_720.jpg" alt="Worktop">
<span>Worktop</span>
</div>
<div class="work-indiv middle">
<img src="https://pixabay.com/static/uploads/photo/2015/12/21/06/41/landscape-1102117_960_720.jpg" alt="Lable">
<span>Lable</span>
</div>
<div class="work-indiv">
<img src="https://pixabay.com/static/uploads/photo/2015/12/21/06/41/landscape-1102117_960_720.jpg" alt="KYIV">
<span>KYIV</span>
</div>


</div>

最佳答案

尝试在媒体查询中移除 .middle 上的左右 padding 以获得较小的屏幕尺寸。

你的代码中有这个:

.middle {
padding-left: 10px;
padding-right: 10px;
width: 783px;
}

试试这个调整:

@media screen and ( max-width: 1200px) {
.middle {
padding-left: 0;
padding-right: 0; }
}

现在,当屏幕尺寸小于 1200 像素宽时,将移除内边距。

Revised Demo

关于html - 调整浏览器大小时对齐 Flexbox 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35511047/

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