简体   繁体   English

使用CSS创建渐变的最简单的跨浏览器兼容方法是什么?

[英]What is the easiest cross-browser compatible way of creating gradients with CSS?

我注意到此服务正在使用它,效果看起来很棒

-moz-linear-gradient(center top , #E3EBF3, #D5E1ED) repeat scroll 0 0 transparent

Use the CSS property like you have in your question. 像在问题中一样使用CSS属性。 Add the -moz , -webkit prefixes, then use it prefixless. 添加-moz-webkit前缀,然后无前缀使用。

IE's filter property can do gradients . IE的filter属性可以进行渐变 It is propriety, but it works :) 这是适当的,但是有效:)

http://www.colorzilla.com/gradient-editor/ http://www.colorzilla.com/gradient-editor/

use modernizr and some if IE blocks at the top to add classes to your html tag so that you can provide valid HTML and CSS, and hacks&properties to those necessary. 使用modernizr和一些IE(如果是IE)在顶部阻止,则将类添加到html标记中,以便您可以提供有效的HTML和CSS,并提供必要的hacks&properties。

for instance, in a gradient I've used in the past: 例如,在过去使用的渐变中:

body {
background: #2688cf;
}
.cssgradients body{
background: -moz-linear-gradient(top, #2688cf 0%, #2989d8 12%, #207cca 14%, #62a2d6 18%, #b9d5ea 28%, #ffffff 40%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#2688cf), color-stop(12%,#2989d8), color-stop(14%,#207cca), color-stop(18%,#62a2d6), color-stop(28%,#b9d5ea), color-stop(40%,#ffffff));
background: -webkit-linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
background: -o-linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
background: linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
}

.ie6 body, .ie7 body, .ie8 body, .ie9 body {
background: -ms-linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#2688cf', endColorstr='#ffffff',GradientType=0 );
background: linear-gradient(top, #2688cf 0%,#2989d8 12%,#207cca 14%,#62a2d6 18%,#b9d5ea 28%,#ffffff 40%);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM