简体   繁体   English

使用HSL颜色定义时出现线性渐变问题

[英]Issue with linear-gradient on when using HSL color definition

I am targeting the latest version of Chrome, I suppose linear-gradient is compatible even without vendor prefix. 我的目标是最新版本的Chrome,我认为即使没有供应商前缀,线性渐变也是兼容的

I have notice that when using HSL colors in the gradient definition prefix must be added otherwise it does no render at all. 我注意到在渐变定义中使用HSL颜色时必须添加前缀,否则它根本不会渲染。

I would like to know: 我想知道:

  • Is this a special case so vendor prefix is a compulsory or it is a browser bug? 这是一个特例,所以供应商前缀是强制性的还是浏览器错误?

 #test { width: 250px; height: 250px; /*works */ background: -webkit-linear-gradient(top, hsl(0, 0%, 100%) 0%, hsla(0, 0%, 100%, 0) 50%, hsla(0, 0%, 0%, 0) 50%, hsl(0, 0%, 0%) 100%), -webkit-linear-gradient(left, hsl(0, 0%, 50%) 0%, hsla(0, 0%, 50%, 0) 100%); /* does no work background: linear-gradient(top, hsl(0, 0%, 100%) 0%, hsla(0, 0%, 100%, 0) 50%, hsla(0, 0%, 0%, 0) 50%, hsl(0, 0%, 0%) 100%), -webkit-linear-gradient(left, hsl(0, 0%, 50%) 0%, hsla(0, 0%, 50%, 0) 100%); */ } 
 <div id="test"></div> 

It is not a bug, you are just using the outdated gradient syntax with the standard property. 这不是一个错误,您只是使用过时的渐变语法与标准属性。 The old one didn't have the to keyword and which was later added. 旧的没有to关键字,后来又添加了。 The MDN page has some history about this change. MDN页面包含有关此更改的一些历史记录。

Quoting the W3C Spec : (note the keyword that I've emphasised) 引用W3C规范 :(注意我强调的关键字)

The linear gradient syntax is: 线性渐变语法是:

<linear-gradient> = linear-gradient( [ [ <angle> | to <side-or-corner> ] ,]? <color-stop>[, <color-stop>]+ ) <linear-gradient> =线性渐变([[<angle> | to <side-or-corner>],]?<color-stop> [,<color-stop>] +)

<side-or-corner> = [left | <side-or-corner> = [left | right] || 对] || [top | [顶部| bottom] 底部]

The old syntax worked by specifying the origin point of the gradient whereas the new syntax works by specifying the destination point , so a value like top should be replaced with to bottom , left with to right , top left with to bottom right etc. 旧语法通过指定渐变的原点来工作,而新语法通过指定目标点来工作 ,因此像top这样的值应该替换to bottomleft to righttop left to bottom right等。

The following snippet which makes the change mentioned above works for me in Chrome v43 and so should work for you in the latest Chrome too. 上面提到的更改的以下代码段适用于我在Chrome v43中,因此也适用于最新的Chrome。

 #test { width: 250px; height: 250px; background: linear-gradient(to bottom, hsl(0, 0%, 100%) 0%, hsla(0, 0%, 100%, 0) 50%, hsla(0, 0%, 0%, 0) 50%, hsl(0, 0%, 0%) 100%), linear-gradient(to right, hsl(0, 0%, 50%) 0%, hsla(0, 0%, 50%, 0) 100%); } 
 <div id="test"></div> 

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

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