In the previous tutorial, we have seen how to apply the fade-in fade-away effect on an HTML element using jQuery. This tutorial will replicate the same effect without using jQuery or any other Javascript functions.
In this example, we do this in CSS by changing the opacity with the hover property. Using CSS, the fade effects can not be provided with the jQuery slow, fast animation effect as we have in the previous tutorial demo.
This short and simple code can fade the image element by using CSS properties. In this code, we have a list of image elements. We are changing these elements’ opacity on mouse-over using the CSS hover property.
<html>
<head>
<title>HTML Element Hover Fade Effect using CSS</title>
<style>
.fadding-photo:hover { opacity:0.4;}
</style>
</head>
<body>
<img class="fadding-photo" src="fading-photo.png" />
<img class="fadding-photo" src="fading-photo1.png" />
<img class="fadding-photo" src="fading-photo2.png" />
</body>
</html>