简体   繁体   English

为什么占位符伪元素上的过渡属性在Chrome中有效?

[英]Why is a transition property on the placeholder pseudoelement valid in Chrome?

I was goofing around with the ::placeholder pseudoelement on Codepen (Chrome 59.0.3071) when I noticed something odd. 当我发现奇怪的东西时,我正在Codepen(Chrome 59.0.3071)上使用::placeholder伪元素来忙。 (please see my JSFiddle ) (请参阅我的JSFiddle

In brief, this CSS should not enable a transition of the ::placeholder color over 2s: 简而言之,此CSS不应使::placeholder颜色过渡2秒以上:

input::placeholder {color:red;transition:2s;}
input:hover::placeholder {color:green}

Using Firefox, there is no color transition over a 2 second interval on hover (this appears to be correct according to this section of a W3C spec and this section of a different one - follow the thread to the ::first-line pseudo-element), but instead there is an immediate color transition to green; 使用Firefox,有超过上悬停2秒的时间间隔内没有颜色转变(这似乎根据正确是本节一个W3C规范的和此部分的不同的一个的-遵循螺纹的::first-line伪元素),而是立即将颜色转换为绿色;

However, the same JSFiddle using Chrome does show a ::placeholder color transition over a period of 2 seconds, which according to the specs, appears to be incorrect. 但是,使用Chrome的同一JSFiddle 确实在2秒内显示::placeholder颜色过渡,根据规格,这似乎是不正确的。

Is this a bug in this version of Chrome (and if so, is it being addressed?) or is this an indictment of my lack of understanding of CSS? 这是此版本的Chrome中的错误(如果是,是否已解决?),或者这是我对CSS缺乏了解的指控?

Currently, it seems that Gecko's and Webkit's implementations are very similar. 当前,Gecko和Webkit的实现似乎非常相似。 The set of allowed rules are slightly different and the default styling isn't the same but those are clearly solvable issues. 允许的规则集略有不同,默认样式也不相同,但这些显然是可以解决的问题。

-- From http://lists.w3.org/Archives/Public/www-style/2013Jan/0283.html -来自http://lists.w3.org/Archives/Public/www-style/2013Jan/0283.html

Non-standard This feature is non-standard and is not on a standards track. 非标准此功能是非标准的,不在标准范围内。 Do not use it on production sites facing the Web: it will not work for every user. 请勿在面向Web的生产站点上使用它:它不适用于每个用户。 There may also be large incompatibilities between implementations and the behavior may change in the future. 实现之间也可能存在很大的不兼容性,并且将来的行为可能会更改。

-- From https://developer.mozilla.org/en/docs/Web/CSS/::-moz-placeholder -来自https://developer.mozilla.org/en/docs/Web/CSS/::-moz-placeholder

Only the subset of CSS properties that apply to the ::first-line pseudo-element can be used in a rule using ::placeholder in its selector. 在规则的选择器中使用::placeholder的规则中,仅适用于::first-line伪元素的CSS属性的子集。

-- From https://developer.mozilla.org/en-US/docs/Web/CSS/::placeholder -来自https://developer.mozilla.org/zh-CN/docs/Web/CSS/::placeholder

But apparently both Chrome and Firefox apply no transitions for ::first-line , as is evident through this JSfiddle I made. 但是显然,Chrome和Firefox都没有为::first-line应用任何过渡,这通过我制作的JSfiddle可以明显看出。

Also while I was searching on the net for answers, I found that the transition property for ::placeholder was working in an older version of Firefox with vendor prefixes which simply reconfirms the line from spec, 同样,当我在网上搜索答案时,我发现::placeholdertransition属性在旧版本的Firefox中起作用,该版本的Firefox具有供应商前缀,可以简单地从规范中确认这一行,

behaviour may change in the future. 将来可能会改变行为。

Here's the code for the JSfiddle. 这是JSfiddle的代码。

 input::-webkit-input-placeholder { color: red; transition: 2s; } input:hover::-webkit-input-placeholder { color: green } p::first-line { color: red; transition: 2s; } p:hover::first-line { color: green } 
 <input placeholder="Sup"> <br /> <p style="display:inline-block">This is the first line.</br> Check it out</p> 

I couldn't find it in the w3c docs. 我在w3c文档中找不到它。 It looks like it used to work in some older Firefox versions. 看起来它曾经可以在某些较旧的Firefox版本中使用。

A workaround with css could be: 使用CSS的解决方法可能是:

input[placeholder]{color:red; transition:color 2.1s;}
input:focus[placeholder]{color:blue}

Which works in Chrome and Firefox. 适用于Chrome和Firefox。

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

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