本文介绍了“传播到视口"是什么意思?在CSS规范中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS规范中有一些章节提到传播到视口";例如:计算高度

什么样的属性可以传播?并与子元素从其父元素继承属性的规则相矛盾吗?

解决方案

如引用所述, overflow属性能够从body传播到html,再从html传播到视口:

可以以这种方式传播的另一个属性是 background :

这种传播行为是出于历史原因(<body background="..." bgcolor="...">)以及使作者能够设置整个页面背景的样式而指定的,这通常不能仅通过htmlbody元素来完成,而无需首先删除其样式默认边距和强制其使用填写页面.

不知道这种行为的尝试将这两个属性应用于bodyhtml的作者可能是,,尤其是当将行为与其他行为进行比较时元素.另一方面,作者还利用这种行为来创建.

此行为与继承没有冲突,因为它的作用方向相反.继承传播"于从父元素到子元素的属性值;此行为会将属性值从子框传播到父框(分别从bodyhtml,并且将html传播到视口).

There are some chapters in the CSS spec mentioning "propagated to the viewport"; for example: calculating the height.

What kind of attribute can propagate? And does it contradict with the rule in which a child element inherits an attribute from its parent?

解决方案

As the quote states, the overflow property is capable of being propagated from body to html, and from html to the viewport:

The other property that can be propagated in this manner is background:

This propagating behavior is specified for historical reasons (<body background="..." bgcolor="...">) as well as to enable authors to style the entire page background, something that cannot normally be done solely through the html or body elements without first removing their default margins and forcing them to fill the page.

Authors not aware of this behavior who try to apply these two properties to body and html may be surprised by the results, especially when comparing the behavior with other elements. On the other hand, authors have also exploited this behavior to create interesting workarounds for browser bugs dating back over 15 years.

This behavior does not conflict with inheritance because it works in the opposite direction. Inheritance "propagates" property values from a parent element to a child element; this behavior propagates property values from a child box to a parent box (body to html, and html to the viewport respectively).

这篇关于“传播到视口"是什么意思?在CSS规范中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 23:59