gpt4 book ai didi

html - 在响应版本中显示 block

转载 作者:行者123 更新时间:2023-11-28 00:22:44 25 4
gpt4 key购买 nike

我有 6 张图片包裹在一个外部 div 中。

我希望在移动版本中每行显示 2 张图片,因此应该有 3 列,每行 2 张图片。

我有这个 HTML:

           * {
box-sizing: border-box;
}

img {
width: auto;
max-width: 100%;
height: auto;
max-height: 100%;
}

.picture-box {
width: 70%; /* limit screen width - max width could have been used aswell */
margin: 0 auto; /* center content */
display: flex;
flex-direction: column;
flex-wrap: wrap;
}

.ring {
padding: 10px;
text-align: center; /* Center ring div */
}

@media screen and (min-width: 1200px) {
.ring {
width: 25%;
}
}

@media screen and (max-width: 1199px) {
.ring {
width: 33.33%;
}
}

@media screen and (max-width: 768px) {
.ring {
width: 50%;
}

.picture-box {
width: 100%;
}
}

.thumb {
display: inline-block;
max-width: 200px;
padding: 10px;
border: 1px solid blue;
}
<div class="picture-box">
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
</div>

Working JSFiddle Example

我试图将 flex-directionrow 更改为 column,但没有帮助。我可能需要为它们写宽度,但不知道如何,现在我不能将它们变成一列。我该如何解决?

最佳答案

这是您要找的吗?

我使用了 width 就像您在问题中询问的那样 - 这是一种方法。

通过这种方式,您可以控制要在每个断点中显示多少个框(.ring's)。

* {
box-sizing: border-box;
}

img {
width: auto;
max-width: 100%;
height: auto;
max-height: 100%;
}

.picture-box {
width: 70%; /* limit screen width - max width could have been used aswell */
margin: 0 auto; /* center content */
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}

.ring {
padding: 10px;
text-align: center; /* Center ring div */
}

@media screen and (min-width: 1200px) {
.ring {
width: 25%;
}
}

@media screen and (max-width: 1199px) {
.ring {
width: 33.33%;
}
}

@media screen and (max-width: 768px) {
.ring {
width: 50%;
}

.picture-box {
width: 100%;
}
}

.thumb {
display: inline-block;
max-width: 200px;
padding: 10px;
border: 1px solid blue;
}
<div class="picture-box">
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
</div>

JSFiddle example

关于html - 在响应版本中显示 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54809355/

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