skip to Main Content

I’m making a panel that has 3 cards and when I hover the mouse over one of the cards, the others become "blur", but :hover:not(:hover) doesn’t work, could anyone tell me how to make it work? Would I have to select another class within the card container to make the others take blur?

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>

I’ll leave the link below too, in case anyone wants to see it and correct it directly there.
Codepen.io

2

Answers


  1. You’re trying to have CSS hover affect sibling elements, which isn’t possible.

    Instead you’ll need to hang the rule on a parent element:

    .card-effects:hover .card-content:not(:hover) {
        filter:blur(.1rem)
    }
    

    In other words: when the element containing all the cards is hovered, blur everything except the specific card that’s also hovered.

    Login or Signup to reply.
  2. I don’t think you can achieve it with only CSS. What I understood from what you said is that you wanted to blur all sibling cards when one card is hovered, which is possible with this:

    .card-effects:hover ~ *:not(:hover){
      filter: blur(.1rem);
    }
    

    But it will only blur the siblings that come after the element, not the previous one.

    You can check the reproducible example here:
    https://jsfiddle.net/rvs8yqxn/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search