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 trialHayden Bradfield
1,797 PointsHow come I cannot get this image overlay to work?
A transparent film with a description is supposed to appear when I hover over the image. What is wrong with my CSS?
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="imgoverlay.css" media="screen">
</head>
<body>
<div id="imgcont">
<img src="frog.jpg" alt="froggy">
<div id="frog">
This is a frog
</div>
</div>
</body>
<html>
CSS
#imgcont {
position:relative;
width:200px;
height:150px;
}
img {
width:200px;
height:150px;
position:absolute;
z-index:0;
}
#frog {
position:absolute;
width:200px;
height:150px;
background: rgba(0,0,0,0.45);
z-index:-1;
}
#frog:hover {
position:absolute;
width:200px;
height:150px;
background: rgba(0,0,0,0.45);
z-index:1
}
2 Answers
Daniel Stopka
13,520 PointsHi,
in #frog:hover statement you want to tell browser, that when you hover your mouse over the image, the z-index will change and the overlay will be visible (will be top layer)...
The problem is that you can't hover on #frog element, as it is hidden behind image.
So you can try to change your code, based on what I wrote before, like:
#imgcont:hover #frog {
z-index:1;
}
so when you hover over #imgcont the z-index in #frog will be 1. I was expecting that #imgcont img:hover should work also, but didn't, not sure why...
Mahmud Kurniawan
7,140 Pointsyou forget the semi-colon mark (;) in the end of "z-index:1" declaration
Hayden Bradfield
1,797 PointsThat didnt help
Hayden Bradfield
1,797 PointsHayden Bradfield
1,797 PointsThat worked! Thanks! Although, I could of not figured that out on my own.