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 trialRamesh Kunwar
Courses Plus Student 4,066 Pointshover image
How to create a dark background with text on hover?
1 Answer
John Lack-Wilson
8,181 PointsThere's a few ways to get what I think you're looking for, but specifically with CSS you will want to use ':hover'.
Example:
.hoverBox {
background-color: white;
color: black;
}
.hoverBox:hover {
background-color: black;
color: white;
}
The above code will change the element with class hoverBox from a white box with black text to a black box with white text on a hover.
Ramesh Kunwar
Courses Plus Student 4,066 PointsRamesh Kunwar
Courses Plus Student 4,066 PointsYeah, I understand this but my image should contain nothing when it is in normal condition. But when I hover the image it should overlap the image with text.
John Lack-Wilson
8,181 PointsJohn Lack-Wilson
8,181 PointsJust so that I understand what it is you're looking for, you want an image to be overlayed with text when it is hovered?
One way you could do it would be:
There's also a content property that you could use, link for how it's used here, however I think the previous transparency method is easier to implement.