CSS背景(渐变)转换不起作用

Jos*_*ase 6 css transition hover css3 css-transitions

我的标签上的CSS转换不是淡入淡出,它就像没有转换一样!我尝试过使用transition: background 300ms ease-in-out;但仍然没有运气

CSS:

.FeatureRow a{
    padding: 10px;
    display: block;
    width: 260px;
    height: auto;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-box-shadow: 0px 4px 8px #f5f5f5;
    -moz-box-shadow: 0px 4px 8px #f5f5f5;
    box-shadow: 0px 4px 8px #f5f5f5;
    background-image: -moz-linear-gradient(top,#fbfbfb,#ffffff);
    background-image: -webkit-gradient(linear,0 0,0 100%,from(#fbfbfb),to(#ffffff));
    background-image: -webkit-linear-gradient(top,#fbfbfb,#ffffff);
    background-image: -o-linear-gradient(top,#fbfbfb,#ffffff);
    background-image: linear-gradient(to bottom,#fbfbfb,#ffffff);
    background-repeat: repeat-x;
    transition: all 300ms ease-in-out;
    -webkit-transition: all 300ms ease-in-out;
    -moz-transition: all 300ms ease-in-out;
    -ms-transition: all 300ms ease-in-out;
    -o-transition: all 300ms ease-in-out;
}
.FeatureRow a:hover{
    background-image: -moz-linear-gradient(top,#C00,#C0F);
    background-image: -webkit-gradient(linear,0 0,0 100%,from(#C00),to(#C0F));
    background-image: -webkit-linear-gradient(top,#C00,#C0F);
    background-image: -o-linear-gradient(top,#C00,#C0F);
    background-image: linear-gradient(to bottom,#C00,#C0F);
}
Run Code Online (Sandbox Code Playgroud)

val*_*als 8

正如Adrift所说,这不受支持; 你必须模拟它.

这是CSS

.FeatureRow {
    padding: 10px;
    display: block;
    position: relative;
    width: 260px;
    height: 70px;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    background-image: linear-gradient(0deg,white,gray);
}

.FeatureRow:after {
    content: '';
    position: absolute;
    left: 0px;
    top: 0px;
    right: 0px;
    bottom: 0px;
    background-image: linear-gradient(0deg,red,magenta);
    opacity: 0;
    transition: all 3s ease-in-out;
}

.FeatureRow:hover:after {
    opacity: 1;
}
Run Code Online (Sandbox Code Playgroud)

我们用一个伪元素覆盖你的div.每个都有一个渐变.伪元素的不透明度设置为0; 当你悬停它时,你将不透明度改为1; 这个属性可以转换.

演示

  • @SethB它确实有效,如果您遇到的问题是文本隐藏在背景后面,请确保将 **z-index: 1** 放在您的 btn 上,并将 **z-index: -1** 放在你的:之后 (2认同)

小智 6

正如其他答案中所述,无法为渐变设置动画。然而,可以为background-color设置动画。知道了这一点,您可以在背景颜色之上叠加一个透明渐变,这将允许您为渐变中的一种颜色设置动画。

为此,请选择要设置动画的颜色,将其设置为background-color,然后将rgba(0,0,0,0)(transparent) 放在其位置。

然后你所要做的就是:hover 或使用 javascriptbackground-color更改 为你想要的值

这仅适用于过渡渐变的一种颜色。但我认为过渡渐变仍然是一个不错的选择

.squareTile {
	background: radial-gradient(#203244eb, rgba(0,0,0,0), #203244eb);
	background-color: #3596ff;
	border-radius: 10px;
  width: 100px;
	height: 100px;
	border: 1px solid black;
	cursor: pointer;
	transition: 1s;
}

.squareTile:hover {
	background-color: #77c577;
}
Run Code Online (Sandbox Code Playgroud)
<div class="squareTile">
</div>
Run Code Online (Sandbox Code Playgroud)

  • 这实际上是一个非常聪明的答案。当然,它不会在非常情况下工作,但要跳出框框思考! (2认同)

adr*_*ift 4

遗憾的是,目前任何浏览器都不支持使用渐变进行动画(或过渡) 。查看“转换”模块中的此列表,了解所有当前可动画属性的列表