本文最后更新于 2024年5月7日,已超过 4 月没有更新,如果文章内容失效,请反馈给我们,谢谢!
效果
代码
HTML
<div class="container_krj">
<div class="box box-1" style="--img: url(https://www.krjojo.com/wp-content/uploads/2024/03/img-1-1.webp);" data-text="Renji"></div>
<div class="box box-2" style="--img: url(https://www.krjojo.com/wp-content/uploads/2024/03/img-2-1.webp);" data-text="Sora"></div>
<div class="box box-3" style="--img: url(https://www.krjojo.com/wp-content/uploads/2024/03/img-3-1.webp);" data-text="Kaito"></div>
<div class="box box-4" style="--img: url(https://www.krjojo.com/wp-content/uploads/2024/03/img-4-1.webp);" data-text="Tsuki"></div>
<div class="box box-5" style="--img: url(https://www.krjojo.com/wp-content/uploads/2024/03/img-5-1.webp);" data-text="Mitsui"></div>
</div>
css
<style>
.container_krj {
position: relative;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
gap: 1em;
height: 500px;
transition: all 400ms;
}
.container_krj:hover .box {
filter: grayscale(100%) opacity(24%);
}
.box {
position: relative;
background: var(--img) center center;
background-size: cover;
transition: all 400ms;
display: flex;
justify-content: center;
align-items: center;
}
.container_krj .box:hover {
filter: grayscale(0%) opacity(100%);
}
.container_krj:has(.box-1:hover) {
grid-template-columns: 3fr 1fr 1fr 1fr 1fr;
}
.container_krj:has(.box-2:hover) {
grid-template-columns: 1fr 3fr 1fr 1fr 1fr;
}
.container_krj:has(.box-3:hover) {
grid-template-columns: 1fr 1fr 3fr 1fr 1fr;
}
.container_krj:has(.box-4:hover) {
grid-template-columns: 1fr 1fr 1fr 3fr 1fr;
}
.container_krj:has(.box-5:hover) {
grid-template-columns: 1fr 1fr 1fr 1fr 3fr;
}
.box:nth-child(odd) {
transform: translateY(-16px);
}
.box:nth-child(even) {
transform: translateY(16px);
}
.box::after {
content: attr(data-text);
position: absolute;
bottom: 20px;
background: #000;
color: #fff;
padding: 10px 10px 10px 14px;
letter-spacing: 4px;
text-transform: uppercase;
transform: translateY(60px);
opacity: 0;
transition: all 400ms;
}
.box:hover::after {
transform: translateY(0);
opacity: 1;
transition-delay: 400ms;
}
</style>
© 版权声明
分享是一种美德,转载请保留原链接
THE END