Hover effect on two classes at the same time and
I am using a class to display an image and I want to add a hover effect in two ways. First, if you hover over the image, the transition effect will display the caption and image overlay.
HTML code:
<div class="xoverlay x-simple"> <img class="x-img-main" src="img/best-img.jpg" />
<div class="xoverlay-box">
<div class="xoverlay-data"> <span class="x-circle x-white"> <a href="#"><i class="fa fa-facebook"></i></a> </span> <span class="x-circle x-white"> <a href="#"><i class="fa fa-twitter"></i></a> </span> <span class="x-circle x-white"> <a href="#"><i class="fa fa-user"></i></a> </span> <span>
<h2 class="hashTag">#hashTag</h2>
<p>It is a long established fact that a reader will be distracted by
the readable content of a page when looking at its layout</p>
<a class="x-more" href="#">More</a></span> </div>
</div>
</div>
and my CSS code:
.xoverlay {
position: relative;
overflow: hidden;
perspective: 300px;
-webkit-perspective: 300px;
-ms-perspective: 300px;
-o-perspective: 300px;
}
.x-simple {
width: 100%;
height: 300px;
}
.x-img-main {
width: 100%;
-webkit-transition: all .45s ease-in-out;
-moz-transition: all .45s ease-in-out;
-o-transition: all .45s ease-in-out;
-ms-transition: all .45s ease-in-out;
transition: all .45s ease-in-out;
}
.x-img-main:hover{
width:110%;
height:auto;
}
.x-simple:hover .xoverlay-box {
width: 100%;
height: 100%;
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
opacity: 1;
background: rgba(27,27,27,.7);
}
+3
source to share
1 answer
The problem in your current code is that the moment you hover the x-simple
element xoverlay-box
appears in front of the img and hover over the img element does not start.
You don't need to hover over two elements to achieve a two-element effect. You can hover over the parent element and use it on the children. In CSS Just replace
.x-img-main:hover{
from
.x-simple:hover .x-img-main{
Changed by JSFiddle
0
source to share