纯css制作相册
使用纯CSS制作相册
纯CSS相册可以通过多种方式实现,以下是几种常见的方法:
基础网格布局
利用CSS Grid或Flexbox创建相册网格布局。以下是一个使用Grid的示例代码:
.photo-album {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 16px;
padding: 16px;
}
.photo {
width: 100%;
height: 200px;
object-fit: cover;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
.photo:hover {
transform: scale(1.05);
}
图片悬停效果
为相册添加交互效果,增强用户体验:
.photo-container {
position: relative;
overflow: hidden;
}
.photo-caption {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: rgba(0,0,0,0.7);
color: white;
padding: 10px;
transform: translateY(100%);
transition: transform 0.3s ease;
}
.photo-container:hover .photo-caption {
transform: translateY(0);
}
相册幻灯片效果
使用CSS动画创建简单的幻灯片效果:
.slideshow {
position: relative;
height: 400px;
overflow: hidden;
}
.slide {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
animation: slideShow 12s infinite;
}
.slide:nth-child(1) { animation-delay: 0s; }
.slide:nth-child(2) { animation-delay: 4s; }
.slide:nth-child(3) { animation-delay: 8s; }
@keyframes slideShow {
0%, 33% { opacity: 1; }
33.01%, 100% { opacity: 0; }
}
响应式设计
确保相册在不同设备上都能良好显示:
@media (max-width: 768px) {
.photo-album {
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.photo {
height: 150px;
}
}
@media (max-width: 480px) {
.photo-album {
grid-template-columns: 1fr;
}
}
图片滤镜效果
为相册图片添加CSS滤镜增强视觉效果:
.photo {
filter: brightness(0.9) contrast(1.1);
transition: filter 0.3s ease;
}
.photo:hover {
filter: brightness(1.1) contrast(1.2) saturate(1.2);
}
这些方法可以单独使用或组合使用,根据具体需求调整样式和效果。纯CSS相册的优势是不依赖JavaScript,性能较好,但交互功能相对有限。







