HTML-CSS: Image overlay on hover
HTML-CSS : Exercise-3 with Solution
Using HTML, CSS create display an image overlay effect on hover.
- Use the :before and :after pseudo-elements for the top and bottom bars of the overlay respectively. Set their opacity, transform and transition to produce the desired effect.
- Use the <figcaption> for the text of the overlay. Set display: flex, flex-direction: column and justify-content: center to center the text into the image.
- Use the :hover pseudo-selector to update the opacity and transform of all the elements and display the overlay.
HTML Code:
Explanation:
- The HTML document contains a figure element displaying an image with an overlay effect on hover.
- The image source is provided using the
tag with the appropriate URL.
- Inside the figure, there is a figcaption element containing a heading with the name of the flower.
- Comments are provided to explain each section of the HTML code, including the purpose of each element and attribute.
- The license information is included as a comment at the beginning of the document.
CSS Code:
Explanation:
- Comments are provided to explain each section of the CSS code, including the purpose of each rule and its styling effects.
- The CSS code defines styles for creating an image overlay effect with hover animation.
- Various properties such as background color, positioning, opacity, and transitions are used to create the desired visual effects.
- The hover effects are applied using the :hover pseudo-class to enhance user interaction with the image.
Go to:
PREV : CSS Properties - Exercises Home
NEXT : Image text overlay.
HTML-CSS Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.