2016-07-30 145 views
0

CSS3渐变不能在所有的浏览器 它适用于Chrome只 我的代码工作CSS3渐变不能在所有的浏览器

<nav class="navbar navbar-default navbar-fixed-top" style="background: -webkit-gradient(linear, 31% 60%, 24% 96%, from(#0071BC), to(#FFFFFF), color-stop(.5,#0071BC)) !important; background: -o-gradient(linear, 31% 60%, 24% 96%, from(#0071BC), to(#FFFFFF), color-stop(.5,#0071BC)) !important; background: -moz-gradient(linear, 31% 60%, 24% 96%, from(#0071BC), to(#FFFFFF), color-stop(.5,#0071BC)) !important; border:2px white solid !important;box-shadow:black 2px 2px 2px;padding-bottom:40px; min-height:100px !important;border-bottom-right-radius: 20% !important;border-bottom-left-radius: 20% !important;"> 

回答

2

请做检查的方式来增加梯度

EX:

<nav class="navbar navbar-default navbar-fixed-top" style="fill: #55bbeb; 
    background: #55bbeb; 
    background: -moz-linear-gradient(90deg, #55bbeb 0%, #84c450 100%); 
    background: -webkit-linear-gradient(90deg, #55bbeb 0%, #84c450 100%); 
    background: -o-linear-gradient(90deg, #55bbeb 0%, #84c450 100%); 
    background: -ms-linear-gradient(90deg, #55bbeb 0%, #84c450 100%); 
    background: linear-gradient(90deg, #55bbeb 0%, #84c450 100%);"> 
+0

请确保没有任何CSS内联@ alberto2000放弃..谢谢! – vignesh

1

首先,您应该将CSS从内联移动到外部CSS文件,以分离HTML和CSS的关注点。然后,正如vignesh指出的那样,您必须考虑浏览器供应商前缀。您可以手动编写它们,但最好的方法是使用某种自动化,我个人推荐SassCompassBourbon或首选,如果您使用Gulp使用gulp-autoprefixer - 这不仅会添加所需的前缀自动,但它也会让你使用更简单的方式来编写css3功能,例如使用mixins的渐变。

2

如果需要从IE9支持,使用SVG(工作在所有其他无IE浏览器一样,所以不需要回退)

div { 
 
    height: 200px; 
 
} 
 
.gradient { 
 
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' version='1.1' height='100' width='100'%3E %3Cdefs%3E %3ClinearGradient id='grad1' x1='0%25' y1='0%25' x2='100%25' y2='0%25'%3E  %3Cstop offset='0%25' style='stop-color:rgb(255,255,0);stop-opacity:1' /%3E  %3Cstop offset='100%25' style='stop-color:rgb(255,0,0);stop-opacity:1' /%3E %3C/linearGradient%3E %3C/defs%3E %3Crect width='100' height='100' fill='url(%23grad1)' /%3E%3C/svg%3E") center/cover; 
 
}
<div class="gradient"></div>

原始SVG(这是urlencoded在上面的示例)

<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='100' width='100'> 
    <defs> 
    <linearGradient id='grad1' x1='0%' y1='0%' x2='100%' y2='0%'> 
     <stop offset='0%' style='stop-color:rgb(255,255,0);stop-opacity:1' /> 
     <stop offset='100%' style='stop-color:rgb(255,0,0);stop-opacity:1' /> 
    </linearGradient> 
    </defs> 
    <rect width='100' height='100' fill='url(#grad1)' /> 
</svg>