<div class="figures">
<figure>
<img src="https://picsum.photos/800/600?random=2" alt="">
</figure>
<figure>
<img src="https://picsum.photos/800/600?random=3" alt="">
</figure>
<figure>
<img src="https://picsum.photos/800/600?random=4" alt="">
</figure>
<figure>
<img src="https://picsum.photos/800/600?random=5" alt="">
</figure>
<figure>
<img src="https://picsum.photos/800/600?random=6" alt="">
</figure>
<figure>
<img src="https://picsum.photos/800/600?random=7" alt="">
</figure>
</div>
<div class="alert">
<p>您的浏览器暂时还不支持CSS的<code>:has</code>选择器。请使用 Safari 15.4 或 Chrome Canary 最新版本查看(^_^)!</p>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
font-family: "Exo", Arial, sans-serif;
background-color: #557;
display: grid;
place-content: center;
gap: 20px;
padding: 80px 20px 20px;
}
img {
max-width: 100%;
height: auto;
object-position: center;
obejct-fit: cover;
}
.figures {
display: grid;
gap: 20px;
grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
transition: all 0.2s ease;
}
figure {
display: flex;
justify-center: center;
align-items: center;
border-radius: 0.5rem;
box-shadow: 0 0.25rem 0.5rem -0.15rem hsla(0 0% 0% / 55%);
background-color: #fff;
background-image: linear-gradient(
135deg,
rgb(240, 105, 102),
rgb(250, 214, 166)
);
margin: 0;
aspect-ratio: 16 / 9;
transition: all 0.2s ease;
cursor: pointer;
}
figure > img {
border-radius: 0.5rem;
}
.figures:has(figure:hover) figure:not(:hover) {
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.15);
z-index: 1;
position: relative;
background: inherit;
transition: all 0.2s ease;
}
.figures:has(figure:hover) figure:not(:hover)::before {
content: "";
position: absolute;
background: rgba(255, 255, 255, 0.25);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
backdrop-filter: blur(4px);
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.18);
z-index: 2;
inset: 0;
transition: all 0.2s ease;
}
.alert {
display: flex;
justify-content: center;
position: fixed;
padding: 1rem;
background-color: #ffeeee;
font-size: 0.75rem;
top: 0;
left: 0;
right: 0;
color: red;
}
.alert code {
display: inline-flex;
padding: 0.25em 0.5em;
font-weight: bold;
background-color: #3f51b5;
color: #fff;
border-radius: 3px;
margin: 0 5px;
}
@supports selector(:has(works)) {
.alert {
display: none;
}
body {
padding: 20px;
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.