简体   繁体   English

CSS渐变未在html5网站中正确应用

[英]CSS gradient not applied correctly in html5 website

I'm using following website ( http://www.colorzilla.com/gradient-editor/ ) to generate a CSS gradient for the background of my website. 我正在使用以下网站( http://www.colorzilla.com/gradient-editor/ )为我的网站背景生成CSS渐变。 In my main CSS file, I put the code like below: 在我的主CSS文件中,将如下代码放入:

body {
    /* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#f77624+0,f9c655+100 */
    background: #f77624; /* Old browsers */
    background: -moz-linear-gradient(left,  #f77624 0%, #f9c655 100%); /* FF3.6-15 */
    background: -webkit-linear-gradient(left,  #f77624 0%,#f9c655 100%); /* Chrome10-25,Safari5.1-6 */
    background: linear-gradient(to right,  #f77624 0%,#f9c655 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f77624', endColorstr='#f9c655',GradientType=1 ); /* IE6-9 */
}

When I refresh index.html file, I only see the background color without the gradient. 刷新index.html文件时,我只会看到没有渐变的background color Is there any error in the CSS code above? 上面的CSS代码是否有错误? If it is any help, I am also using the HTML5 Boilerplate . 如果有帮助,我还将使用HTML5 Boilerplate

css gradient code will work only at latest browser.. will not work less than IE9, NO issue with above code.. just clear the history of browser .. css渐变代码仅在最新的浏览器上有效。.不能低于IE9,上述代码没有问题..只需清除浏览器的历史即可..

 body { /* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#f77624+0,f9c655+100 */ background: #f77624; /* Old browsers */ background: -moz-linear-gradient(left, #f77624 0%, #f9c655 100%); /* FF3.6-15 */ background: -webkit-linear-gradient(left, #f77624 0%,#f9c655 100%); /* Chrome10-25,Safari5.1-6 */ background: linear-gradient(to right, #f77624 0%,#f9c655 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f77624', endColorstr='#f9c655',GradientType=1 ); /* IE6-9 */ } .wrapper { width: 95vw; height: calc(95vw * 9/16); max-height: 95vh; max-width: calc(95vh * 16/9); background: center; background-size:contain; margin: auto; position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #lorem { color: aqua; font-size:10vmin; text-align:center; position:absolute; transform: translate(-50%, -50%); top: 50%; left: 50%; margin:auto; } 
 <div class="wrapper"> <p id="lorem"> This text should scale with div only. </p> </div> 

created sample : https://jsfiddle.net/70fq44sv/5/ 创建的示例: https : //jsfiddle.net/70fq44sv/5/

This is for reference only. 仅供参考。

it's possible to use SVG for gradient backgrounds. 可以SVG用于渐变背景。 it's supported by all modern browsers. 所有现代浏览器都支持它。

You can view the source of an SVG background to see how it's structured in this live example created by MDN 您可以查看SVG背景的来源,以查看其在MDN创建的此实时示例中的结构

They scale well and eliminate the need for browser prefixes. 它们可以很好地扩展,并且不需要浏览器前缀。

in the example below I created an SVG and then encoded it into base64 to eliminate the additonal http request 在下面的示例中,我创建了一个SVG,然后将其编码为base64,以消除附加的http request

 .cooldiv { background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxsaW5lYXJHcmFkaWVudCBpZD0iZyIgeDE9IjAlIiB4Mj0iMTAwJSIgeTE9IjAlIiB5Mj0iMTAwJSI+PHN0b3Agc3R5bGU9InN0b3AtY29sb3I6IHJnYigyMjEsMTUwLDg2KTsiIG9mZnNldD0iMCIvPjxzdG9wIHN0eWxlPSJzdG9wLWNvbG9yOiByZ2IoNTIsMTI3LDE0OSk7IiBvZmZzZXQ9IjEiLz48L2xpbmVhckdyYWRpZW50PjxyZWN0IHN0eWxlPSJmaWxsOiB1cmwoI2cpOyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIvPjwvc3ZnPg==); width: 100vw; height: 100vh; } 
 <div class="cooldiv"></div> 

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

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