简体   繁体   English

如何使用CSS在悬停时滑动图像?

[英]How do I slide the image on hover with CSS?

I wanna slide images from the top of images to bottom with css. 我想用CSS将图像从图像顶部滑动到底部。 Actually I write some codes. 其实我写一些代码。 But, I dont wanna write specific pixel for sliding. 但是,我不想写用于滑动的特定像素。

I dont want this: 我不想要这样:

transform:translate3d(0px,-150px,0px); 

I want like this: 我想要这样:

transform:translate3d(0px,AUTO,0px);

Here is my css: 这是我的CSS:

.work
{
    width:100%;
    height:350px;
    float:left;
    margin-bottom:10px;
    border:2px solid #e5e5e5;
    overflow:hidden
}

.work img
{
    width:100%;
    -moz-transition:all .6s;
    -webkit-transition:all .6s;
    transition:all .6s;
    transform:translate3d(0px,0px,0px)
}

.work img:hover
{
    transform:translate3d(0px,-150px,0px);
    margin:0
}

Here is my html: 这是我的html:

<div class="work">
   <a href="http://example.com">
      <img src="http://anlamli-guzelsozler.com/wp-content/uploads/2015/05/krt-manzara-resimleri.jpg">
      <div>Example</div>
   </a>
</div>

How can I do this? 我怎样才能做到这一点?

Use percentages instead. 请改用百分比。 Check this out! 看一下这个!

It need not be specific pixels as you say- on img:hover if I say 100% height, it will mean the whole image height. 不必像您在img:hover所说的那样是特定的像素,如果我说100%的高度,则表示整个图像的高度。

 .work { width: 100%; float: left; margin-bottom: 10px; border: 2px solid #e5e5e5; overflow: hidden } .work img { display: block; width: 100%; -moz-transition: all .6s; -webkit-transition: all .6s; transition: all .6s; transform: translate3d(0px, 0px, 0px) } .work:hover img { transform: translate3d(0px, -100%, 0px); margin: 0 } 
 <div class="work"> <a href="http://example.com"> <img src="http://anlamli-guzelsozler.com/wp-content/uploads/2015/05/krt-manzara-resimleri.jpg"> </a> </div> 

EDIT: Put a display: block; 编辑:放一个display: block; on the img element and you can get rid of the whitespace below the image too! img元素上,您也可以摆脱图片下方的空白!

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

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