Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

element hover not working properly in css3 fade effects

I am working on a simple project where a single block element hover will show 4x zoom element. I did it through pure css and css3 transition. See the jsfiddle demo . There will be four element , each has different hover element. But when I hover on it only one hover element is showing though it is not associate with that block or element.

Check the demo to make yourself an opinion.

.main {
  position: relative;
  width: 300px;
  overflow: hidden
}

.main a {
  width: 50%;
  height: 50%;
  float: left;
}

.main a .child {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  background: gray;
  filter: alpha(opacity=0);
  opacity: 0;
  -webkit-transition: opacity 0.5s ease-out;
  -moz-transition: opacity 0.5s ease-out;
  -ms-transition: opacity 0.5s ease-out;
  -o-transition: opacity 0.5s ease-out;
  transition: opacity 0.5s ease-out;
}

.main a:hover .child {
  -webkit-transition: opacity 0.2s ease-in;
  -moz-transition: opacity 0.2s ease-in;
  -ms-transition: opacity 0.2s ease-in;
  -o-transition: opacity 0.2s ease-in;
  transition: opacity 0.2s ease-in;
  zoom: 1;
  filter: alpha(opacity=100);
  opacity: 1.0;
}
<div class="main">
  <a href="">
    <img src="http://placehold.it/150x150">
    <div class="child">
      <h4>1.Text</h4>
    </div>
  </a>
  <a href="">
    <img src="http://placehold.it/150x150">
    <div class="child">
      <h4>2.Text</h4>
    </div>
  </a>
  <a href="">
    <img src="http://placehold.it/150x150">
    <div class="child">
      <h4>3.Text</h4>
    </div>
  </a>
  <a href="">
    <img src="http://placehold.it/150x150">
    <div class="child">
      <h4>4.Text</h4>
    </div>
  </a>

</div>

Demo project on JSFiddle

Important note: if i use display none or block in hover instate the css3 transition then it is working fine, But i need the fade effect.

like image 435
Zinan Nadeem Avatar asked Oct 31 '22 03:10

Zinan Nadeem


1 Answers

the problem here is that the four .child element is showed when hover on a element, but only the last .child is visible, to resolve this isue use visibility property instead display:

https://jsfiddle.net/f9m1mnce/

.main{
	position: relative;
	width: 300px;
	overflow:hidden	
}
.main a{
	width: 50%;
	height: 50%; 
	float:left;
}
.main a > .child{
	position: absolute; 
	left:0;
	right:0;
	bottom:0;
	top: 0;
    visibility: hidden;
	background: gray;
	filter: alpha(opacity=0);
	opacity: 0;
	-webkit-transition: opacity 0.5s ease-out;
	-moz-transition: opacity 0.5s ease-out;
	-ms-transition: opacity 0.5s ease-out;
	-o-transition: opacity 0.5s ease-out;
	transition: opacity 0.5s ease-out;					
}
.main a:hover > .child{
	-webkit-transition: opacity 0.2s ease-in .2;
	-moz-transition: opacity 0.2s ease-in .2 ;
	-ms-transition: opacity 0.2s ease-in .2;
	-o-transition: opacity 0.2s ease-in .2;
	transition: opacity 0.2s ease-in .2; 
    top: 0;
    visibility: visible;
	zoom: 1;
	filter: alpha(opacity=100);
	opacity: 1.0;
}
<div class="main">
	<a href="">
		<img src="http://placehold.it/150x150">
		<div class="child">
			<h4>1 Lorem Ipsum is simply dummy text of the printing and typesetting industry.</h4>
		</div>
	</a>
	<a href="">
		<img src="http://placehold.it/150x150">
		<div class="child">
			<h4>2 Lorem Ipsum is simply dummy text of the printing and typesetting industry.</h4>
		</div>
	</a>
	<a href="">
		<img src="http://placehold.it/150x150">
		<div class="child">
			<h4>3 Lorem Ipsum is simply dummy text of the printing and typesetting industry.</h4>
		</div>
	</a>
	<a href="">
		<img src="http://placehold.it/150x150">
		<div class="child">
			<h4>4 Lorem Ipsum is simply dummy text of the printing and typesetting industry.</h4>
		</div>
	</a>
	
</div>
like image 145
xzegga Avatar answered Nov 11 '22 04:11

xzegga