以下是使用CSS创建图片廊:
响应式图片廊
使用 CSS3 的媒体查询来创建响应式图片廊:
<style>
div.img {
border: 1px solid #ccc;
}
div.img:hover {
border: 1px solid #777;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
@media only screen and (max-width: 700px){
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
@media only screen and (max-width: 500px){
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
</style>
<body>
<div class="responsive">
<div class="img">
<a target="_blank" href="#">
<img loading="lazy" src="/uploads/2022/1/4aeef5e5-e2d1-4e4b-96a8-bc450f4d53a4.png" alt="Trolltunga Norway" >
</a>
<div class="desc">这里添加图片文本描述</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="#">
<img loading="lazy" src="/uploads/2022/1/4aeef5e5-e2d1-4e4b-96a8-bc450f4d53a4.png" alt="Forest" >
</a>
<div class="desc">这里添加图片文本描述</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="#">
<img loading="lazy" src="/uploads/2022/1/4aeef5e5-e2d1-4e4b-96a8-bc450f4d53a4.png" alt="Northern Lights" >
</a>
<div class="desc">这里添加图片文本描述</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_mountains.jpg">
<img loading="lazy" src="/uploads/2022/1/4aeef5e5-e2d1-4e4b-96a8-bc450f4d53a4.png" alt="Mountains">
</a>
<div class="desc">这里添加图片文本描述</div>
</div>
</div>
<div class="clearfix"></div>
</body>
讨论区