Here is an example of how to change an image on hover using CSS:
HTML:
<div class="image-container">
<img class="normal" src="image1.jpg" alt="image1">
<img class="hover" src="image2.jpg" alt="image2">
</div>
CSS:
.image-container {
position: relative;
}
.image-container img {
display: block;
width: 100%;
}
.image-container img.hover {
display: none;
}
.image-container:hover img.normal {
display: none;
}
.image-container:hover img.hover {
display: block;
}
In this example, the .image-container
class is used to create a container for the images. The img.normal
and img.hover
classes are used to specify the normal and hover images respectively. The :hover
pseudo-class is used to change the display property of the images when the container is hovered over.
Also Read:
- How To Remove White Space Under An Image Using CSS
- What are Pseudo Elements And Pseudo Classes?
- Which CSS Property Is Used To Change The Face Of A Font?
- How To Change Background Opacity Without Affecting Text
- Change The Cursor Into A Hand When A User Hovers Over A List Item?
- How To Horizontally Center A DIV With CSS