i want to add background color overlay effects when hovering on the image.But i have tried few times with css pseudo-class:after
, it is just not working, the code as:
<div class="test">
<img src="assets/img/slide1.jpeg" class="overlay" alt="">
<!-- my image tag -->
</div>
the css:
.test{
width: 50%;
height: 50%;
}
.overlay{
width: 100%;
height: 100%;
position: relative;
}
.overlay:after{
content: "test";
position: absolute;
font-size:3em;
}
the .overlay:after
content is not showing up, but it is working when i am using :after
class on the <p>
or <span>
tag, and i was intend to adding overlay color effects on my <img>
tag as:
/*adding background color on the image tag using :after*/
.overlay:after{
content: " ";
position: absolute;
width: 100%;
height: 100%;
background-color: red;
z-index: 0;
}
So my questions are:
1. Why the pseudo class :after
not working on the img tag but working with the text tag such as <p>
or<h1>
?
2. Is there anything wrong with my code on adding red bg color using :after
?