【读CSS规范】层叠的问题

Declarations apply if the associated selector matches the element in question and the target medium matches the media list on all @media rules containing the declaration and on all links on the path through which the style sheet was reached.

这句看了别人的翻译,不知是不是翻译的有问题,无法理解,求教。

阅读 2.6k
2 个回答

前面两个很好理解嘛,就是匹配选择器和媒体查询。最后的是指带媒体查询的 import ,如 @import url("fancyfonts.css") screen;

这句话还真的不太好理解。

这句的前一句不是说,找出所有的适用于当前元素的 declarations (样式声明)么。 这一整句就是解释哪些是适用的样式声明。

适用的样式声明是指,样式声明的选择选择器匹配当前元素并且样式声明所在的@meda匹配当前的显示媒质。。后面半句我实在是揉不到这句话里面了。

适用的样式包括两条:1、选器匹配; 2、媒质(media)也匹配。 这是第一个and链接了这两句。可以声明介质的有两个地方,@media@import 所以media liston @meda 和(第二个and)on link

path which was reached 是因为@import是可以添加显示媒质作为条件导入的,所以有些@import的CSS可能不能reach,那么这一部分规则就不能适用。这里就是说,是通过当前媒质作为条件能达到的link才算是适用的声明(适用声明的其中一个条件)。

Declarations apply,
   if the associated selector matches the element in question &&
      the target medium matches the media list 
           on all @media rules containing the declaration 
           on all links on the path through which the style sheet was reached.

太复杂,不知道说清楚没。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题