Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Transitions and Transforms Transition Timing Functions and Delays Change a Transition's Speed with Timing Functions

Blur the image without blurring the overlay

Hi,

I would like to make a container that looks very similar to the containers in the video but (first row) I want it to also blur the image in the background on hover with filter: blur(). So, image is blurred, background of the div (photo-overlay) is set to rgba(0,0,0,.65) and paragraph is overlayed on that. I can't make it without bluring the whole photo-overlay div because image is inner and I'm hovering on outer div. How can I do that with pure css?

Jacob Herrington
Jacob Herrington
15,835 Points

Try it yourself, make a CodePen, JSFiddle, or JSBin and post it here so we can give you direction -- you'll learn more by hacking at it yourself first.

Here's CodePen link -> http://codepen.io/anon/pen/KNPjrx

So as I said before... I would like to blur background image on hover without bluring photo-overlay class. I can't figure out how to do that. Thanks in advance for your help!

1 Answer

Jacob Herrington
Jacob Herrington
15,835 Points

To achieve the effect you are looking for, change this:

.photo img:hover {
  filter: blur(10px);
}

To this:

.photo:hover>img {
  filter: blur(10px);
}

The first CSS snippet essentially says, "Child element of .photo that is an img change when you are hovered over." The problem is that the img tag cannot be hovered over because the .photo-overlay element is in the way. So you need to change the CSS to say, "When the .photo element is hovered over, change the child element that is an image."

You can read more about selectors and the cool extra things they can do here. I'm sure one of the CSS courses on Treehouse covers this as well, but I haven't taken it yet.

That's exactly what I was looking for! I forget about those selectors. I should refresh some lessons with Gil. Really appreciate your help. ;)