Is it possible to write one CSS rule for several prefixed selectors?

强颜欢笑 提交于 2019-12-01 20:03:36

Short answer: no. This behaviour is accordance with the W3C spec (see 4.1). That is if any selector list contains one or more selectors that are invalid, the entire selector list is considered invalid, hence you cannot group browser-specific selectors.

Warning: the equivalence is true in this example because all the selectors are valid selectors. If just one of these selectors were invalid, the entire selector list would be invalid. This would invalidate the rule for all three heading elements, whereas in the former case only one of the three individual heading rules would be invalidated.

According to Firefox, the selector has errors; unrecognised pseudo classes. So the rule is ignored in its entirety, as per the definition.

Ditto for webkit and IE.

So the solution is to split these across multiple rules, as the answer to the other question indicates.

::-webkit-input-placeholder {
    color:    #999;
}
:-moz-placeholder,::-moz-placeholder {
    color:    #999;
}
:-ms-input-placeholder {
    color:    #999;
}

As you can see, you can put both the -moz- ones in the same rule, because Firefox recognises them both. (They also mean the same thing, so having them both in the rule is redundant, but it works, so it doesn't matter.)

Fiddle

Edit: as shown in the comments, the single-colon version of the Mozilla selectors doesn't work, only the double colon version does. (in the latest version that is, don't have older versions here). But the single-colon version is not considered an error, otherwise this CSS wouldn't have worked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!