In CSS, create a hover effect that blurs all child elements except the one being hovered on. This effect should

I've encountered a challenge with blurring all children of a parent when hovering over a specific child. While I've made some progress in achieving this effect, the previous child does not get blurred if you hover over the second child, for example:

.child {
  height: 50px;
  width:100px;
}
.child:nth-child(1) {
  background-color: red;
}.child:nth-child(2) {
  background-color: yellow;
}.child:nth-child(3) {
  background-color: blue;
}.child:nth-child(4) {
  background-color: green;
}

.parent > .child:hover ~ .child:not(:hover) {
  filter: blur(15px);
}
<div class="parent">
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
</div>

My goal is to blur all children except the one being hovered over when selecting the second, third, or last child. Is there a way to achieve this using just CSS since a previous child selector doesn't exist? Am I overlooking something?

Answer №1

A definite possibility exists, provided you target both the parent and child elements in the following manner:

Specifically, trigger a hover effect on the parent element (it registers when the child is hovered over) and designate the non-hovered children to appear blurry.

.child {
  height: 50px;
  width:100px;
}
.child:nth-child(1) {
  background-color: red;
}.child:nth-child(2) {
  background-color: yellow;
}.child:nth-child(3) {
  background-color: blue;
}.child:nth-child(4) {
  background-color: green;
}

.parent:hover .child:not( :hover ) {
  filter: blur(15px);
}
<div class="parent">
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
  <div class="child"></div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There appears to be an issue with the functionality of the external CSS pathway

placeholder image hereplaceholder image hereplaceholder image here I'm encountering a problem and struggling to identify the mistake in my current approach. ...

What is the best way to bring an HTML element to the front?

I recently added a moving clouds background using CSS3 to my website. You can check out examples of similar backgrounds at the following links: However, I have encountered an issue where the clouds are overlapping the text on my site, making it unreadable ...

Step-by-step guide on clipping a path from an image and adjusting the brightness of the remaining unclipped area

Struggling to use clip-path to create a QR code scanner effect on an image. I've tried multiple approaches but can't seem to get it right. Here's what I'm aiming for: https://i.stack.imgur.com/UFcLQ.png I want to clip a square shape f ...

Displaying markers on a Google map by fetching data from a MySQL database in PHP

The image attached here serves as an example. You can view it here. Currently, I display locations on a map in an HTML page with static code like: Here is the JavaScript code to load the map on the page: <script type="text/javascript" src="https://ma ...

What steps can be taken to prevent users from dragging a page horizontally?

One function on my site involves a horizontal scroll that animates the DIV to the left when a button is clicked. The element's width is set at 18000px, ensuring it has a horizontal scrollbar that I have since disabled. Despite this, users are still ...

Issue with getting Bootstrap sticky-top to function on sidebar column

My goal is to implement a sticky sidebar on the right side of the page. The sidebar menu is contained within a grid column. I have attempted to utilize the sticky-top class, following the guidance provided in this question, but unfortunately, it does not s ...

Steps to reposition an element with absolute positioning to the upper left corner of the screen

I am currently in the process of creating a hamburger menu without using JavaScript, which should drop down from the top to the bottom when clicked. The burger menu is situated at the top right corner of the screen, but every time I try to drop down the na ...

Is there a way to leverage JavaScript to click on one div and modify the settings of another div simultaneously?

I am struggling with my code which has unnecessary information. <div> <div id="one" class="button"></div> <div id="two" class="button"></div> </div> <div> <div class="Home tab"> < ...

What causes the disparity in functionality between CSS's Left 75% and Right 25% properties?

Here is my CSS code snippet: .bloodparam > .highvalue { bottom: 12px; right: 25%; } and .bloodparam > .highvalue { bottom: 12px; left: 75%; } I expected the element to be in the same position with both lines of code, but I'm noticing differe ...

Expanding the CSS Search Box

Visit the link I've been working on coding a CSS text box. When you hover over the button in the provided link, you'll notice that the 'Type to search' functionality is working smoothly as it moves to the right. My current focus is on ...

Photo frame edge

I am in the process of creating a basic website using HTML and CSS. My current task involves taking an image and using it as a page border. Unfortunately, I am unable to share my progress at this moment because I am unsure of where to begin. I understand ...

Looking for assistance in determining a solution for progress bar implementation

Currently, I am developing a simple application using web technologies like HTML, CSS, and jQuery Mobile. This app enables me to create goals and save them to a listview using the <li> element. Every <li> representing a goal will have an assoc ...

Is there a way to have a span update its color upon clicking a link?

I have 4 Spans and I'm looking to create an interactive feature where clicking a link in a span changes the color of that span. Additionally, when another link in a different span is clicked, the color of that span changes while reverting the previous ...

The React Material UI table is having trouble stretching to fill the space

Currently, I am experimenting with developing my own virtualization technique using a different approach than react-virtualized. However, I am encountering difficulties when it comes to styling. I have come across an issue where the material table in the ...

Adjusting the appearance of Google charts

Is there a way to eliminate the label for the area chart located at the top right corner? ...

Tips for hiding a div element until its visibility is toggled:- Set the display property of

Looking for some guidance on this jQuery code I'm working with to create a toggle menu. The goal is to have the menu hidden when the page loads, and then revealed when a button is clicked. However, currently the menu starts off being visible instead o ...

Collecting Information from the DOM to Append to an Array with JavaScript

My aim is to create a fully functional shopping cart using either vanilla JavaScript or jQuery. I'm uncertain if I'm approaching it the right way, but here's my plan: Firstly, I want to establish an array named cartItems to store all sho ...

What is the best way to adjust the width and height of react-flip-page through CSS for different media queries?

Incorporating the react-flip-page npm package to add animation to a book on my web application has been exciting. However, I've encountered an issue with adjusting the width when using media queries due to the available props for setting size and colo ...

Angular 2: Change Boolean value depending on a condition

I find myself facing a challenge with a search-bar feature. My goal is to display all the filtered names when the input value reaches a length of 2 or more characters. After successfully extracting the value.length from the input field, I encountered a ro ...

Creating a split color background in CSS with a perfectly centered image on top

Is there a way to center and scale just one image on a webpage, rather than two? I want it to be in the middle of the screen or page and resize with the window. Image example: https://i.sstatic.net/t0AQP.png body { font-family: 'Titillium Web&a ...