I am struggling with implementing an overlay effect on two images on my website.
My goal is to add an overlay when the images are clicked, and I have tried creating this effect using the after
pseudo class.
Unfortunately, the overlay does not seem to work as expected in my demo. Can someone help me identify where I might be making a mistake?
Demo: https://jsfiddle.net/vu0hntuf/
jQuery(".option").on('click',function() {
jQuery(this).toggleClass('option optionActive');
});
.option::after, .optionActive::after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
color: #FFF;
}
.optionActive::after {
display: block;
background: rgba(0, 0, 0, .6);
}
.col-md-4 {
margin-bottom: 30px;
margin-left: 0;
margin-right: 0;
}
@media (min-width: 768px) {
.col-md-4 {
flex: 0 0 33.33333%;
max-width: 33.33333%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="col-md-4">
<div class="option">
<img src="http://placehold.it/200x200" class="debttype" data-type_id="1">
</div>
</div>
<div class="col-md-4">
<div class="option">
<img src="http://placehold.it/200x200" class="debttype" data-type_id="1">
</div>
</div>