CSS 子选择器是 W3C 标准吗?
像这样的子选择器:
#id > a
{
background-color: blue;
}
w3schools css 网站上似乎没有引用。这是不好的做法吗?
Child selectors like this:
#id > a
{
background-color: blue;
}
Doesn't seem to be referenced on the w3schools css website. Is it bad practice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,但是 IE6 不支持,这对某些人来说仍然是一种限制网站。
No, but it is not supported by IE6, which still is kind of a limitation for some sites.
是的,它们符合标准。
http://www.w3.org/TR/CSS21/selector.html #child-selectors
如前所述,它们不适用于 IE6。如果您可以从您的网站获取指标并确定 IE6 用户的比例是否值得额外的开发工作。如果没有,请尝试定义您的用户群,以粗略猜测他们可能使用的浏览器。如果做不到这一点,请尝试让它以一种模糊优雅的方式回落,这样至少该网站仍然可用,即使它看起来不像您想要的那么好。
Yes, they're in the standard.
http://www.w3.org/TR/CSS21/selector.html#child-selectors
As mentioned they don't work on IE6 though. If you can grab metrics from your site and determine if the proportion of IE6 users is worth the extra development effort. If not try and define your user base to make a rough guess as to the browsers they're likely to use. Failing that, try make it fall back in a vaguely graceful way so at the very least the site is still usable even if it doesn't look quite as good as you would like.
是的,子选择是标准的一部分,如此处所示CSS2。
Yes, child selects are part of the standard as seen here for CSS2.
为了回答您的问题,子选择器并不是不好的做法,并且在某些情况下非常有用。它们也符合 CSS 2 标准。旧版浏览器 (IE6) 不支持它们,但所有现代浏览器都可以使用它们。
附带说明:W3Schools 不以任何方式隶属于 W3C。如果您想了解有关实际标准的更多详细信息,您应该直接访问 W3C 网站。
To answer your question, child selectors are not bad practice and can be very useful is certain situations. They are also in the CSS 2 standard. They are not supported by older browsers (IE6), but all modern browsers can use them.
As a side note: W3Schools is not affiliated in any way with the W3C. If you want more detailed information on the actual standards, you should go directly to the W3C's website.