gpt4 book ai didi

html - Css 网格图像

转载 作者:太空宇宙 更新时间:2023-11-04 12:40:53 24 4
gpt4 key购买 nike

我想用css创建一个网格布局来像马赛克一样显示不同高度的图像。我使用下面的html代码

<div id="photos">
<a href="../media/images/0.jpg"><img src="../media/images/0.jpg" alt="Little doggie"></a>
<img src="../media/images/1.jpg" alt="Little kittie">
<img src="../media/images/2.jpg" alt="Little kittie">
<img src="../media/images/3.jpg" alt="Little doggie">
<img src="../media/images/4.jpg" alt="Little kittie">
<img src="../media/images/5.jpg" alt="Little kittie">
<img src="../media/images/6.jpg" alt="Little doggie">
<img src="../media/images/7.jpg" alt="Little kittie">
<img src="../media/images/8.jpg" alt="Little kittie">
<img src="../media/images/9.jpg" alt="Little doggie">
<img src="../media/images/10.jpg" alt="Little kittie">
<img src="../media/images/11.jpg" alt="Little kittie">
<img src="../media/images/12.jpg" alt="Little doggie">
<img src="../media/images/13.jpg" alt="Little kittie">
<img src="../media/images/14.jpg" alt="Little kittie">
<img src="../media/images/15.jpg" alt="Little doggie">
<img src="../media/images/16.jpg" alt="Little kittie">
<img src="../media/images/17.jpg" alt="Little kittie">
<img src="../media/images/18.jpg" alt="Little doggie">
<img src="../media/images/19.jpg" alt="Little kittie">
<img src="../media/images/20.jpg" alt="Little kittie">
<img src="../media/images/21.jpg" alt="Little doggie">
<img src="../media/images/22.jpg" alt="Little kittie">
<img src="../media/images/23.jpg" alt="Little kittie">
<img src="../media/images/24.jpg" alt="Little doggie">
<img src="../media/images/25.jpg" alt="Little kittie">
<img src="../media/images/26.jpg" alt="Little kittie">
<img src="../media/images/27.jpg" alt="Little doggie">
<img src="../media/images/28.jpg" alt="Little kittie">
<img src="../media/images/29.jpg" alt="Little kittie">
<img src="../media/images/30.jpg" alt="Little doggie">
<img src="../media/images/31.jpg" alt="Little kittie">
<img src="../media/images/32.jpg" alt="Little kittie">
<img src="../media/images/33.jpg" alt="Little doggie">
<img src="../media/images/34.jpg" alt="Little kittie">
<img src="../media/images/35.jpg" alt="Little kittie">
<img src="../media/images/36.jpg" alt="Little doggie">
<img src="../media/images/37.jpg" alt="Little kittie">
<img src="../media/images/38.jpg" alt="Little kittie">
<img src="../media/images/39.jpg" alt="Little doggie">
<img src="../media/images/40.jpg" alt="Little kittie">
<img src="../media/images/41.jpg" alt="Little kittie">
<img src="../media/images/42.jpg" alt="Little doggie">
<img src="../media/images/43.jpg" alt="Little kittie">
<img src="../media/images/44.jpg" alt="Little kittie">
<img src="../media/images/45.jpg" alt="Little doggie">

</div>

和CSS

#photos {
/* Prevent vertical gaps */
line-height: 0;

-webkit-column-count: 5;
-webkit-column-gap: 5px;
-moz-column-count: 5;
-moz-column-gap: 5px;
column-count: 5;
column-gap: 5px;


}
#photos img {
/* Just in case there are inline attributes */
margin-top:4px;
width: 100% !important;
height: auto !important;
-webkit-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;

}

#photos img:hover{
transform:scale(1.5);
}

@media (max-width: 1200px) {
#photos {
-moz-column-count: 4;
-webkit-column-count: 4;
column-count: 4;
}
}
@media (max-width: 1000px) {
#photos {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
}
}
@media (max-width: 800px) {
#photos {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
}
@media (max-width: 400px) {
#photos {
-moz-column-count: 1;
-webkit-column-count: 1;
column-count: 1;
}
}

但是当我在 mozilla 上运行它时,它不会工作,而且当图像缩放几次时它会消失,留下白色的空白区域。有什么不对?这是 jsfiddle

最佳答案

检查它:-

#photos img {
/* Just in case there are inline attributes */
margin-top:4px;
width: 20% !important;
height: auto !important;
-webkit-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
float:left

}

DEMO

关于html - Css 网格图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26883222/

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