gpt4 book ai didi

html - 带有 CSS 的灵活缩略图网格

转载 作者:太空狗 更新时间:2023-10-29 13:49:41 24 4
gpt4 key购买 nike

我正在尝试使用均匀的“填充”在屏幕上定位缩略图。这是一张说明问题的图片:

page preview

<!DOCTYPE html>
<html>
<head>
<title>Test rows</title>

<style type="text/css">

body {
background: #121212;
color: #fff;
}

#Container {
background: #585858;
margin: 0 auto;
min-width: 1024px;
width: 85%;
margin-top: 50px;

text-align: justify;
-ms-text-justify: distribute-all-lines;
text-justify: distribute-all-lines;
}

#Container a {
vertical-align: top;
display: inline-block;
*display: inline;
zoom: 1;
}

.stretch {
width: 100%;
display: inline-block;
font-size: 0;
line-height: 0;
}




</style>
</head>

<body>

<div id="Container">

<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<a href="#"><img src="http://dummyimage.com/200x120/444/fff" /></a>
<span class="stretch"></span>

</div>




</body>
</html>

我在 stackoverflow 中做了一些研究并找到了一些有用的代码来开始,但我面临着一些问题。我希望图像从左到右对齐,而不是在最后一行中的图像较少时“捕捉”到容器的边框,如您所见。

我还希望行之间的“垂直间距”等于图像之间的水平间距,现在我有一些像“3px”这样的垂直间距,但我不确定这是从哪里来的。如果需要,我愿意接受 js 解决方案。谢谢

最佳答案

会不会有什么LIKE THIS为你工作?

这是基于提供的答案 here on SO我建议您阅读,以及 this one - 也基于它。这证明子元素。

HTML

<div id="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<span class="stretch"></span>
</div>

CSS

#container {

text-align: justify;
-ms-text-justify: distribute-all-lines;
text-justify: distribute-all-lines;

/* just for demo */

}

.box {
width: 150px;
height: 125px;
background:#ccc;
vertical-align: top;
display: inline-block;
*display: inline;
margin:10px;
zoom: 1
}
.stretch {
width: 100%;
display: inline-block;
font-size: 0;
line-height: 0
}

或者,如果您希望它们从左到右对齐而不是对齐子项,请查看this fiddle , 基于 this answer on SO

HTML

<div class="container">
<div>Box1</div>
<div>Box2</div>
<div>Box3</div>
<div>Box4</div>
<div>Box5</div>
<div>Box6</div>
<div>Box7</div>
<div>Box8</div>
<div>Box9</div>
<div>Box10</div>
<div>Box11</div>
</div>

CSS

* {
margin: 0;
padding: 0;
}
.container {
overflow: auto;
display: block;
}
.container > div {
margin: 20px;
width: 150px;
height: 100px;
background: blue;
float: left;
color: #fff;
text-align: center;
}

关于html - 带有 CSS 的灵活缩略图网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20607812/

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