我正在制作一个包含 3 张卡片的面板,当我将鼠标悬停在其中一张卡片上时,其他卡片会变得“模糊”,但是 :hover:not(:hover) 不起作用,任何人都可以告诉我如何让它起作用?我是否必须在卡片容器中选择另一个类别才能使其他类别变得模糊?
below I will leave a good part of the css ```:root {
--green-neon: #7adf67;
--green-neon-s: #30a026;
--purple-neon: #a676f9;
--purple-neon-s: #885af7;
--blue-neon: #0a3e58;
--blue-neon-s: #387598;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: sans-serif;
}
body {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
height: 100svh;
background: #101010;
gap: 2rem;
}
.card-effects {
position: relative;
}
.card-effects .stick-neon {
content: '';
position: absolute;
min-width: 10px;
min-height: 30%;
border-radius: 1rem;
z-index: -1;
filter: blur(.2rem);
transition: all .4s;
}
/* STICKS COLORS*/
.green-stick {
background: var(--green-neon);
box-shadow: 0 0 1rem #ffffff35, 0 0 2.5rem var(--green-neon-s), 0 0 4.5rem var(--green-neon-s);
}
.blue-stick {
background: var(--blue-neon);
box-shadow: 0 0 1rem #ffffff35, 0 0 2.5rem var(--blue-neon-s), 0 0 4.5rem var(--blue-neon-s);
}
.purple-stick {
background: var(--purple-neon);
box-shadow: 0 0 1rem #ffffff35, 0 0 2.5rem var(--purple-neon-s), 0 0 4.5rem var(--purple-neon-s);
}
.card-effects .stick-neon:last-child {
top: -10%;
left: 90%;
height: 45%;
}
.card-effects .stick-neon:first-child {
bottom: -10%;
left: 15%;
height: 40%;
}
.card-effects:hover .stick-neon {
left: 50%;
min-height: 65%;
rotate: 90deg;
}
.card-content:hover:not(:hover) {
filter: blur(.1rem);
}
.card-effects:hover .stick-neon:first-child {
bottom: -40%;
}
.card-effects:hover .stick-neon:last-child {
top: -40%;
}
.card-content {
width: 16rem;
height: 20rem;
display: flex;
align-items: center;
flex-direction: column;
border-radius: 1rem;
justify-content: space-evenly;
box-shadow: inset 0 0 6.75rem #ffffff10;
backdrop-filter: blur(.8rem);
transition: box-shadow .3s;
}
.card-content:hover {
box-shadow: inset 0 0 3rem #ffffff30;
}
.card-content img {
width: 90%;
height: 45%;
aspect-ratio: 16/9;
border-radius: .8rem;
object-fit: cover;
}
.card-content p {
text-align: justify;
color: #fff;
width: 90%;
}
@media only screen and (max-width: 900px) {
body {
flex-direction: column;
gap: 5rem;
}
}
<div class="card-effects">
<span class="green-stick stick-neon"></span>
<div class="card-content">
<img src="https://images.unsplash.com/photo-1562704613-25321c60487b?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDExMDQ1MzF8&ixlib=rb-4.0.3&q=85" alt="">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quos perferendis aperiam et libero!</p>
</div>
<span class="green-stick stick-neon"></span>
</div>
<div class="card-effects">
<span class="stick-neon blue-stick"></span>
<div class="card-content">
<img src="https://images.unsplash.com/photo-1536183922588-166604504d5e?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDExMDQ2MzJ8&ixlib=rb-4.0.3&q=85" alt="">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quos perferendis aperiam et libero!</p>
</div>
<span class="stick-neon blue-stick"></span>
</div>
<div class="card-effects">
<span class="stick-neon purple-stick"></span>
<div class="card-content">
<img src="https://images.unsplash.com/photo-1698250403749-8d3e0e5f507b?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDEwOTk4NDR8&ixlib=rb-4.0.3&q=85" alt="">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quos perferendis aperiam et libero!</p>
</div>
<span class="stick-neon purple-stick"></span>
</div>
我也会在下面留下链接,以防有人想看到它并直接在那里更正。 Codepen.io
您试图让 CSS 悬停影响同级元素,这是不可能的。
相反,您需要将规则挂在父元素上:
.card-effects:hover .card-content:not(:hover) {
filter:blur(.1rem)
}
换句话说:当整个块悬停时,模糊除悬停的特定卡片之外的所有内容。