gpt4 book ai didi

html - 当窗口变小时 Div 不内联?

转载 作者:行者123 更新时间:2023-11-28 03:37:30 26 4
gpt4 key购买 nike

我有几个 div 的小问题。我设置了 5 个不同颜色的 div,当窗口大小缩小时,div 一个接一个地落在彼此下面。有没有一种方法可以缩小它们之间的空间,使它们靠得更近?

再次感谢各位

p {
margin: 0;
}

.pageColourOn {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 155px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.pageColourOff {
display: none;
}

#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}

#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}

.bg01Off {
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}

.bg02Off {
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}

.bg03Off {
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}

.bg04Off {
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}

.bg05Off {
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}

.center {
text-align: center;
}
<div class="pageColourOn" id="pageColour">
<div id="pageName">
<p>Colour</p>
</div>
<div class="center">
<div id="bg01" class="bg01Off">
</div>
<div id="bg02" class="bg02Off">
</div>
<div id="bg03" class="bg03Off">
</div>
<div id="bg04" class="bg04Off">
</div>
<div id="bg05" class="bg05Off">
</div>
</div>

最佳答案

将容器 center 更改为具有以下属性的 flexbox:

.center {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
padding: 0 4%
}

p {
margin: 0;
}

.pageColourOn {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 155px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.pageColourOff {
display: none;
}

#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}

#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}

.bgOff {
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}

.bg01Off {
background-color: #80b3ff;
}

.bg02Off {
background-color: #afe9af;

}

.bg03Off {
background-color: #ffb380;
}

.bg04Off {
background-color: #ffaaaa;
}

.bg05Off {
background-color: #eeaaff;
}

.center {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
padding: 0 4%
}
<div class="pageColourOn" id="pageColour">
<div id="pageName">
<p>Colour</p>
</div>
<div class="center">
<div id="bg01" class="bgOff bg01Off">
</div>
<div id="bg02" class="bgOff bg02Off">
</div>
<div id="bg03" class="bgOff bg03Off">
</div>
<div id="bg04" class="bgOff bg04Off">
</div>
<div id="bg05" class="bgOff bg05Off">
</div>
</div>

关于html - 当窗口变小时 Div 不内联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44392955/

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