简体   繁体   English

CSS悬停过渡

[英]css hover over transition

I have one question about my css hover effect. 关于我的CSS悬停效果,我有一个问题。

This is my DEMO page from codepen . 这是我来自codepen DEMO页面。

The problem is hover over image. 问题是将鼠标悬停在图像上。 If you click my demo page then you see what is wrong in my script. 如果单击我的演示页面,那么您会发现我的脚本出了什么问题。

When you hover over the image with your mouse first image is ok but when you move mouse another image my gradient color moving left. 当您将鼠标悬停在图像上时,可以选择第一个图像,但是当您将鼠标移到另一个图像上时,我的渐变颜色将向左移动。

Anyone knows solution ? 有人知道解决方案吗?

This is my CSS code for image hover transition and gradient color: 这是我的图像悬停过渡和渐变颜色的CSS代码:

.abo_im {
  float:left;
  width:170px;
  height:150px;
overflow:hidden;
  -webkit-transition: all .3s ;
        -moz-transition: all .3s ;
        -ms-transition: all .3s ;
        -o-transition: all .3s ;
        transition: all .3s ;


}
.abo_im  img.height {
   width: 100%;
   height:auto;

}
.abo_im img {
  width:100%; 

}
.abo_im:hover {
  width:120%; 
  margin: 0 0 0 -10%; 
        -moz-transition: all .3s ;
        -ms-transition: all .3s ;
        -o-transition: all .3s ;
        transition: all .3s ;   
}
.gradient_c {
  position:absolute;
  width:170px;
  height:150px;
   z-index:1;
  background: -moz-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));
  background: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));

    }

The element div.gradient_c is absolutely positioned and doesn't adhere to the overflow: hidden; 元素div.gradient_c绝对位置,并且不遵循overflow: hidden; add relative positioning to its parent and increase the width - updated demo 向其父级添加相对位置并增加其宽度- 更新了演示

.abo_im {
    position: relative;
}
.gradient_c {
    width: 186px;
}

Update The problem is that you are adjusting an element with positioned decedents. 更新问题是您正在调整具有定位后代的元素。 They follow the increase width appearing as though they are moving 他们跟随增加的宽度,好像在移动

Changing .abo_im:hover to .abo_im:hover img will only affect the width of the image. .abo_im:hover更改为.abo_im:hover img仅会影响图像的宽度。 Demo 演示版

change the width property it should work 更改它应该工作的width属性

.gradient_c {
  position:absolute;
  width:auto;//change this
  height:150px;
   z-index:1;
  background: -moz-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));
  background: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM