为什么可以为不同的浏览器我岂不组特定的浏览器的CSS选择器? [英] Why can I not group browser-specific CSS-selectors for different browsers?

查看:151
本文介绍了为什么可以为不同的浏览器我岂不组特定的浏览器的CSS选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试着写了下面的规则,以样式支持它的浏览器中输入占位符:

I just tried to write the following rule to style the input placeholder for browsers that support it:

#main input::-webkit-input-placeholder,
#main input:-moz-placeholder
{
    color: #888;
    font-style: italic;
}

的问题是,不应用该规则。不过,如果我打破它,这样,而不是它工作得很好:

The problem is that the rule isn't applied. However, if I break it up like this instead it works just fine:

#main input::-webkit-input-placeholder
{
    color: #888;
    font-style: italic;
}
#main input:-moz-placeholder
{
    color: #888;
    font-style: italic;
}

为什么我不能组特定浏览器的选择,还是有另一种方式来做到这一点?它感觉不对两次重复相同的属性为相同的元素。

Why can I not group browser-specific selectors, or is there another way to do it? It doesn't feel right to repeat the same attributes twice for the same element.

更新:

刚刚发现这个资源的说,它不能做,但为什么至今没有消息。这似乎很奇怪,浏览器应该放弃整个规则只是因为它不承认其中一个选择。

Just found this resource stating that it cannot be done, but so far no information on why. It seems odd that the browser should have to discard the entire rule just because it doesn't recognize one of the selectors.

推荐答案

如果一组选择的一个选择是无效的,浏览器必须把整个规则为无效。或者至少让说,W3C

If one selector in a group of selectors is invalid, the browser must treat the entire rule as invalid. Or at least so says the W3C.

我不知道为什么这种行为是硬性规定,但一推,我猜这是因为一个无效的选择可能会破坏一般CSS语法,因此无法对浏览器能够可靠地猜出无效选择结束和有效元素开始。

I'm not sure why this behaviour is mandated, but at a push, I'd guess it's because an invalid selector could break general CSS syntax, making it impossible for a browser to reliably guess where the invalid selector ends and valid elements begin.

这篇关于为什么可以为不同的浏览器我岂不组特定的浏览器的CSS选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆