gpt4 book ai didi

javascript - 如何折叠不同高度的柱子

转载 作者:太空宇宙 更新时间:2023-11-04 09:09:16 25 4
gpt4 key购买 nike

在我的网站上,我有 6 列图像。每个都有相同数量的图像,但由于图像的高度不同,所以所有列的高度都不同。

这很好,除非我试图让它响应。当屏幕变小时,我将最后 3 列折叠到前 3 列下方。列向左浮动,所以我只使用

clear:left;

第4列实现了这个。但是,当我这样做时,列之间存在间隙......

enter image description here

我需要消除这个差距。我希望下面的列接触上面的列。我怎样才能做到这一点?这可以仅使用 CSS 来完成吗?

列有以下...

.imageWrap-col {
float: left;
max-width: 16%;
}

并且列容器有overflow:auto...

#gallery {
height: 100%;
width: 100%;
position: fixed;
overflow-y: auto;
}

最佳答案

你可以试试column CSS

body {/* or any container */
-moz-column-width:180px;
column-width:180px;
column-gap:0.2em;
max-width:800px;/* enough to hold four columns */
margin:auto;
}
img {
width:100%;/* or same value as column-width */
}

/* demo purpose */

html:before {
content:' see snippet in fullpage, then resize window';
display:block;
text-align:center;
font-size:1.6em;
}
<img src="http://dummyimage.com/150x110"/>
<img src="http://dummyimage.com/150x150"/>
<img src="http://dummyimage.com/150x250"/>
<img src="http://dummyimage.com/350x150"/>
<img src="http://dummyimage.com/150x110"/>
<img src="http://dummyimage.com/150x150"/>
<img src="http://dummyimage.com/150x250"/>
<img src="http://dummyimage.com/350x150"/>
<img src="http://dummyimage.com/150x110"/>
<img src="http://dummyimage.com/150x150"/>
<img src="http://dummyimage.com/150x250"/>
<img src="http://dummyimage.com/350x150"/>
<img src="http://dummyimage.com/150x110"/>
<img src="http://dummyimage.com/150x150"/>
<img src="http://dummyimage.com/150x250"/>
<img src="http://dummyimage.com/350x150"/>
<img src="http://dummyimage.com/150x110"/>
<img src="http://dummyimage.com/150x150"/>
<img src="http://dummyimage.com/150x250"/>
<img src="http://dummyimage.com/350x150"/>

它适用于任何容器和任何类型的盒子:

div {
-moz-column-width: 200px;
column-width: 200px;
column-gap: 0.2em;
}
figure,
img {
display: inline-block;
width: 100%;
margin: 0;
}
figure {
border: solid;
box-sizing: border-box;
margin-bottom: 0.2em;
}
figcaption,
h1 {
text-align: center;
padding: 1em;
}
<div>
<h1>see snippet in fullpage, then resize window</h1>
<figure>
<img src="http://dummyimage.com/150x110" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x250" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/350x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x110" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x110" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x250" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/350x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x250" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/350x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x110" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x250" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/350x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x110" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x250" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/350x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x110" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x250" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/350x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x110" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x150" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/150x250" />
<figcaption>
caption text
</figcaption>
</figure>
<figure>
<img src="http://dummyimage.com/350x150" />
<figcaption>
caption text
</figcaption>
</figure>
</div>

关于javascript - 如何折叠不同高度的柱子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42237411/

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