<html> vs. <body> element in css

Summary

  • The html and body elements are distinct block-level entities, in a parent/child relationship.
  • The html element’s height and width are controlled by the browser window.
  • It is the html element which has (by default) overflow:auto, causing scrollbars to appear when needed.
  • The body element is (by default) position:static, which means that positioned children of it are positioned relative to the html element’s coordinate system.
  • In almost all modern browsers, the built-in offset from the edge of the page is applied through a margin on the body element, not padding on the html element.

重要的一点:html 的宽和高 由浏览器窗口控制

block-level elements which don’t have a specific height applied to themautomatically grow in height to accommodate their content. What happens when a height is applied? It depends on the value of the CSS overflow property

块级元素默认没有特别指定高度,根据包裹其中的内容自动增长高度,如果为其指定高度,接下来发生的事就要取决于 overflow 这个属性的值了。


html 元素 默认 overflow 熟悉为 auto,但是没有指定它的高,为什么会出现scrollbar?

The html element is a little bit special. Its height and width are governed by the window/frame it’s in. When you increase your window width, the fixed width of the html element is increased; when you make the window taller, so increases the height of the html element.

观点来自于:

点击打开链接




<html> vs. <body> element in css

相关文章:

你感兴趣的文章:

标签云: