CSS背景颜色转换向上滑动 [英] CSS background colour transition slide up

查看:502
本文介绍了CSS背景颜色转换向上滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用CSS转换来更改悬停时元素的背景颜色。我想通过让它从底部向上滚动。我可以褪色使用这个背景,但我想它向上滑动:

  -webkit-transition:background-color 0.5s线性; 
-moz-transition:background-color 0.5s linear;
-o-transition:background-color 0.5s linear;
transition:background-color 0.5s linear;对不起,我对CSS不太好。










$ b b

另一个想法,最好是向上滚动一个单独的元素,并应用背景。



感谢任何帮助

解决方案

为了向上滑动背景颜色,您需要使用背景图片或某种渐变,同时逐渐调整 background-position

  .box {
width:200px; height:100px;
background-size:100%200%;
background-image:linear-gradient(to bottom,red 50%,black 50%);
transition:background-position 1s;
}

.box:hover {
background-position:0 -100%;
}

您可以在这里看到这个演示:http://jsfiddle.net/as5ZU/


I am trying to change the background colour of a element on hover by using CSS transitions. I want to do this by having it scroll up from the bottom. I can fade the background in using this, but I would like it to slide up:

-webkit-transition: background-color 0.5s linear;
-moz-transition: background-color 0.5s linear;
-o-transition: background-color 0.5s linear;  
transition: background-color 0.5s linear;

Sorry I'm not very good at CSS.

One other thought, would it be better to scroll up a separate element with the background applied to it.

Thanks for any help

解决方案

In order to slide the background color up you would need to use a background image, or a gradient of some sort, while gradually adjusting the background-position:

.box {
    width: 200px; height: 100px;
    background-size: 100% 200%;
    background-image: linear-gradient(to bottom, red 50%, black 50%);
    transition: background-position 1s;
}

.box:hover {
    background-position: 0 -100%;
}

You can see this demo here: http://jsfiddle.net/as5ZU/

这篇关于CSS背景颜色转换向上滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆