带有背景渐变的 CSS 过渡
我正在学习 CSS3 的动画/过渡,但在这段代码中过渡不起作用......为什么?
HTML:
<div id="test">
</div>
CSS:
#test {
background-color: #333;
background-image: -webkit-linear-gradient(top, #333, #666);
width: 100px;
height: 100px;
-webkit-transition: background 1s linear;
}
#test:hover {
background-image: -webkit-linear-gradient(top, #666, #999);
}
I'm learning about animations/transitions with CSS3, but in this code the transition don't worked... why?
HTML:
<div id="test">
</div>
CSS:
#test {
background-color: #333;
background-image: -webkit-linear-gradient(top, #333, #666);
width: 100px;
height: 100px;
-webkit-transition: background 1s linear;
}
#test:hover {
background-image: -webkit-linear-gradient(top, #666, #999);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这对我来说是应该的。有几件事,如果您希望它在其他浏览器中工作,则这只适用于 google chrome:
这是一个生成器
这是一个解释
编辑
抱歉,我没有'没有意识到那里那里有一个
transition
属性。在进行了一些谷歌搜索并自己尝试了一些东西之后,很明显背景渐变的过渡是不可能的......但是。这里有一篇很好的文章,介绍了如何通过一点技巧让它工作
http: //nimbupani.com/some-css-transition-hacks.html
This works for me as it should intended. A couple things, this will only work in google chrome if you want it to work in other browsers:
Here is a generator
Here is an explanation
edit
Sorry I didn't realize there was a
transition
property in there. After doing some googling and trying some stuff out on my own, it is pretty clear that transitions on background gradients isn't possible... yet.Here is a good article on how to get it to work with a little bit of a hack
http://nimbupani.com/some-css-transition-hacks.html
它对我来说效果很好。你用标签包裹了css文件吗?
its working fine on me. have you wrapped the css file with tag?
它对我有用,我还可以向您指出 CSS3 游乐场,您可以在其中即时检查它
CSS3游乐场
It worked for me, Also I can point you to the CSS3 playground where you can check it on the fly
CSS3 Playground
渐变过渡可以通过一点点“作弊”来完成。我绝对不是CSS方面的专家(而且我是新来的,所以不要很快恨我:D),但只需将div放在彼此之上,一个不透明度为1,第二个为0。
(每个 div 设置了不同的渐变)悬停时,将不透明度从 1 更改为 0,反之亦然。
设置计时功能,然后将这些 div 放置在彼此的 z-index 属性上,完成其余的工作。
(针对 Safari 进行了优化)也许是菜鸟的方式,但这(令人惊讶地)完美地工作:
以及无论它应该看起来如何的 div:
Gradient transition can by done with little bit of "cheating". I am definitely not pro in css stuff (and I am new here so don't hate me fast :D ), but just place to divs on top of each other, one with opacity 1 and second with 0.
(Each div has set different gradients) On hover, change opacity from 1 to 0 and vice versa.
Set timing function and however these divs are placed on each other z-index property do the rest.
(Optimized for Safari) Maybe rookie way, but this works (surprisingly) perfectly:
and whatever-it-should-look-like divs: