带有线性渐变的 CSS 过渡
我正在尝试向一个按钮添加一个过渡,该按钮的背景是用 css 线性渐变制作的,但它不起作用。
这是我的按钮的 CSS。
a.button
{
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,@green), color-stop(100%,#a5c956));
-webkit-transition: background 5s linear;
}
a.button:hover
{
-webkit-gradient(linear, left top, left bottom, color-stop(0%,@greenhover), color-stop(100%,#89af37))
}
如果您想知道 @green 和 @greenhover,我正在使用 .less 来制作我的 css。
这有什么问题吗?有什么想法吗?
I'm trying to add a transition to a button I have that's background is made with css linear-gradient but it's not working.
This is the css for my button.
a.button
{
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,@green), color-stop(100%,#a5c956));
-webkit-transition: background 5s linear;
}
a.button:hover
{
-webkit-gradient(linear, left top, left bottom, color-stop(0%,@greenhover), color-stop(100%,#89af37))
}
If you're wondering about @green and @greenhover, I'm using .less to make my css.
Anything wrong with this? Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
遗憾的是,您现在确实无法过渡渐变。
因此,唯一可行的解决方法是使用具有所需渐变和过渡的额外元素(其不透明度):
Sadly, you really can't transition gradients for now.
So, the only workable workaround is using an extra element with needed gradient and transition it's opacity:
这很棘手..当然棘手很酷;)
好吧..我找到了解决方案。它基本上是通过令人惊叹的
:before
选择器完成的有一个非常棒的样式;)
it's tricky.. and of course tricky is cool ;)
okay.. i got a solution. and it's basically done via amazing
:before
selectorhave a nice awesome styling ;)
我知道这很老了,但我还找不到任何好的解决方案。所以这是我的解决方案
首先在 ":before 上制作渐变并使用不透明度隐藏它,然后在悬停时过渡不透明度 1。
https://jsfiddle.net/sumon380/osqLpboc/3/
I know this pretty old but I could not find any good solution yet. So here is my solution
First Make gradient on ":before and hide it with opacity then transition opacity 1 on hover.
https://jsfiddle.net/sumon380/osqLpboc/3/
您可以使用投影来伪造渐变过渡!
例如,在我的一页中:
接下来是:
在这里,您实质上使用了嵌入阴影作为类似 Photoshop 的蒙版,从而在底层元素上产生渐变效果。悬停时,效果会反转。
You can fake gradient transitions using drop shadows!
For instance, from one of my pages:
Followed by:
Here, you are essentially using an inset shadow as a Photoshop-like mask, causing a gradient effect on the underlying element. On hover, you invert the effect.
如果您在悬停按钮时进行轻微突出显示,则有一个更简单的解决方案。您可以将渐变稍微向下微调,并使背景颜色与渐变的顶部颜色相同: http:// /cdpn.io/oaByI
我知道它非常有限,但如果适用于该用例。
If you're doing the slight highlight when hovering the button there is a much simpler solution. You can just nudge the gradient down a bit and have the background-color be the same as the top color of your gradient: http://cdpn.io/oaByI
It's pretty limited I know, but if works well for that use case.
我知道这个问题已经很老了,但我找到了一种很好的方法来动画基本渐变,该方法在某些情况下有效。
此方法可让您对渐变颜色的变化进行动画处理,但不能对颜色停止位置的变化进行动画处理。
https://jsfiddle.net/62vzydeh/
HTML:
CSS:
I know this question is pretty old, but I found a good way to animate basic gradients that will work in some cases.
This method will let you animate a change in color of the gradient but not a change in the position of the color stops.
https://jsfiddle.net/62vzydeh/
HTML:
CSS:
9 年了,但这一次,希望我的
styled-components
可以帮助某人:并开始使用您新设计的组件以获得额外的效果!感谢@kizu 的建议。
9 years, but this time, hope my
styled-components
can help someone:And start using your new designed component with extra effect! Thanks to @kizu for the suggestion.
您必须在源中具有相同的样式并在目标中更改样式。
喜欢
you must have same style in source and changed style in target.
like