在 Bootstrap 导航中设置 CSS 渐变动画
Animate CSS Gradient in Bootstrap nav
我正在使用 bootstrap atm 并注意到我简单的 css 导航按钮转换不起作用。
我把它归结为 bootstrap 但后来删除了我的渐变背景并且只有纯色背景并且它起作用了。
是否有 CSS 梯度过渡的规范,是否存在?有什么办法可以做到这一点?如果没有,最好的解决方案是什么?
下面是我的 fiddle 渐变是橙色悬停。
http://jsfiddle.net/MgcDU/10245/
渐变如下,所以在多个浏览器中都有些效果。
background: -webkit-gradient(linear, 0 0, 0 100%, from(rgba(254, 204, 177, 1)), color-stop(0.5, rgba(241, 116, 50, 1)), color-stop(0.51, rgba(234, 85, 7, 1)), to(rgba(251, 149, 94, 1)));
background: -webkit-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: -moz-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: -o-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#feccb1', endColorstr='#fb955e', GradientType=0);
linear-gradient
在纯色起作用的地方失败的原因是因为 linear-gradient
实际上创建了一个图像。它对应的正写属性是background-image
,不是background-color
.
A background-image
不是过渡性的,但是使用定位和伪元素,我们可以使用 opacity
属性 来模拟它。这是一个展示此技术的简单示例。
示例:
li {
display: inline-block;
width: 200px;
height: 200px;
background: black;
text-align: center;
line-height: 200px;
font-size: 40px;
/*Must have positioning.*/
position: relative;
}
li a {
color: white;
/*Must have positoning.*/
position: relative;
}
li:before {
/*Make it fill the container.*/
content: "";
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
/*Create gradient.*/
background: rgb(254, 204, 177);
background: -webkit-gradient(linear, 0 0, 0 100%, from(rgba(254, 204, 177, 1)), color-stop(0.5, rgba(241, 116, 50, 1)), color-stop(0.51, rgba(234, 85, 7, 1)), to(rgba(251, 149, 94, 1)));
background: -webkit-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: -moz-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: -o-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
/*Transition the opacity.*/
opacity: 0;
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-o-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
}
li:hover:before {
opacity: 1;
}
<li>
<a href="#">test</a>
</li>
我正在使用 bootstrap atm 并注意到我简单的 css 导航按钮转换不起作用。
我把它归结为 bootstrap 但后来删除了我的渐变背景并且只有纯色背景并且它起作用了。
是否有 CSS 梯度过渡的规范,是否存在?有什么办法可以做到这一点?如果没有,最好的解决方案是什么?
下面是我的 fiddle 渐变是橙色悬停。
http://jsfiddle.net/MgcDU/10245/
渐变如下,所以在多个浏览器中都有些效果。
background: -webkit-gradient(linear, 0 0, 0 100%, from(rgba(254, 204, 177, 1)), color-stop(0.5, rgba(241, 116, 50, 1)), color-stop(0.51, rgba(234, 85, 7, 1)), to(rgba(251, 149, 94, 1)));
background: -webkit-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: -moz-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: -o-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#feccb1', endColorstr='#fb955e', GradientType=0);
linear-gradient
在纯色起作用的地方失败的原因是因为 linear-gradient
实际上创建了一个图像。它对应的正写属性是background-image
,不是background-color
.
A background-image
不是过渡性的,但是使用定位和伪元素,我们可以使用 opacity
属性 来模拟它。这是一个展示此技术的简单示例。
示例:
li {
display: inline-block;
width: 200px;
height: 200px;
background: black;
text-align: center;
line-height: 200px;
font-size: 40px;
/*Must have positioning.*/
position: relative;
}
li a {
color: white;
/*Must have positoning.*/
position: relative;
}
li:before {
/*Make it fill the container.*/
content: "";
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
/*Create gradient.*/
background: rgb(254, 204, 177);
background: -webkit-gradient(linear, 0 0, 0 100%, from(rgba(254, 204, 177, 1)), color-stop(0.5, rgba(241, 116, 50, 1)), color-stop(0.51, rgba(234, 85, 7, 1)), to(rgba(251, 149, 94, 1)));
background: -webkit-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: -moz-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: -o-linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
background: linear-gradient(rgba(254, 204, 177, 1) 0%, rgba(241, 116, 50, 1) 50%, rgba(234, 85, 7, 1) 51%, rgba(251, 149, 94, 1) 100%);
/*Transition the opacity.*/
opacity: 0;
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-o-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
}
li:hover:before {
opacity: 1;
}
<li>
<a href="#">test</a>
</li>