gpt4 book ai didi

html - 我怎样才能让 float imgs 填满所有空间

转载 作者:太空宇宙 更新时间:2023-11-04 14:20:44 26 4
gpt4 key购买 nike

我有一些图像宽度固定大小。我希望它们像网格一样填满,如下所示:

enter image description here

但是这会发生:

enter image description here

我怎样才能让它们填满一切?

html:

<div id="product-pics">
<img src="img/dummy/282x282.png" alt="" class="tile" />
<img src="img/dummy/566x282.png" alt="" class="tile" />
<img src="img/dummy/282x282.png" alt="" class="tile" />
<img src="img/dummy/282x282.png" alt="" class="tile" />
<img src="img/dummy/282x566.png" alt="" class="tile" />
<img src="img/dummy/282x282.png" alt="" class="tile" />
<img src="img/dummy/282x282.png" alt="" class="tile" />
<img src="img/dummy/282x282.png" alt="" class="tile" />
<img src="img/dummy/566x282.png" alt="" class="tile" />
</div>

CSS:

.tile {
margin: 1px;
float: left; /* to remove the 4px gap between images */
}

最佳答案

在这种情况下,您需要稍微更改 HTML 中的顺序。将 282x566 放在第一位,然后只向右浮动那个。让其余部分 float 到左侧,它应该可以工作。

DEMO

重新排列 HTML:

<div id="product-pics">
<img src="img/dummy/282x566.png" alt="282x566" class="tile double-h right" />

<img src="img/dummy/282x282.png" alt="282x282" class="tile" />
<img src="img/dummy/282x282.png" alt="282x282" class="tile" />
<img src="img/dummy/282x282.png" alt="282x282" class="tile" />
<img src="img/dummy/282x282.png" alt="282x282" class="tile" />

<img src="img/dummy/566x282.png" alt="566x282" class="tile double-w" />
<img src="img/dummy/282x282.png" alt="282x282" class="tile" />
</div>

相关CSS:

#product-pics { width: 852px; }
.tile {
float: left;
width: 282px;
height: 282px;
margin: 0 2px 2px 0;
}
.right { float: right; }
.double-h { height: 566px; }
.double-w { width: 566px; }

关于html - 我怎样才能让 float imgs 填满所有空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12262765/

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