简体   繁体   English

css根元素边距

[英]css root element margin

In css html element is said to be the root element, 在css中, html元素被认为是元素,
and as I'm reading in this article its width and height are governed by the browser window/frame. 正如我在本文中所读到的那样,它的宽度和高度由浏览器窗口/框架控制。

So, does it make any sense to apply margins to it ? 那么,应用保证金是否有意义呢?

I think it doesn't because if it is the root element it's not supposed to be contained in a higher level element. 我认为它不是因为如果它是根元素,它不应该包含在更高级别的元素中。

Howewer every browser allows you to add margin to html element, any explainations ? Howewer每个浏览器允许你添加边距到HTML元素,任何解释?

The phrogz.net article is simply wrong. phrogz.net文章完全错了。 That's really not how it works at all. 这根本不是它的工作方式。 The html element is a block-level element which can be styled pretty much like any other block level element. html元素是一个块级元素,可以像任何其他块级元素一样进行样式设置。

Your page is painted on a canvas of (logically) infinite dimensions which has an origin at point (0, 0). 您的页面绘制在(逻辑上)无限维度的画布上,其原点位于点(0,0)。 The browser has a viewport which shows an area of the canvas. 浏览器有一个视口 ,显示画布的一个区域。 There exists a rectangular block called the Initial Containing Block whose top left hand corner is at (0, 0) and has a height and width equal to that of the viewport. 存在一个称为初始包含块的矩形块,其左上角位于(0,0)并且其高度和宽度等于视口的高度和宽度。 The root element's position and dimensions can be specified relative to the Initial Containing Block, just as any other block element's position and dimensions can be specified relative to its containing block . 根元素的位置和尺寸可以相对于初始包含块指定,就像任何其他块元素的位置和尺寸可以相对于其包含块指定一样。


As an aside, CSS is not just about HTML. 顺便说一句,CSS不只是关于HTML。 It will work with a DOM created in any namespace from any source. 它将与任何来源的任何命名空间中创建的DOM一起使用。 In particular it will work with DOMs created from XML. 特别是它将与从XML创建的DOM一起使用。 So the root element is not necessarily the <html> element. 所以根元素不一定是<html>元素。

It doesn't make sense to add margins to the <HTML> element. 将边距添加到<HTML>元素没有意义。 You should only add margins to the <body> and the elements that are in it. 您应该只为<body>及其中的元素添加边距。 Check also http://www.w3.org/TR/html401/struct/global.html#h-7.3 for the spec 有关规范,请查看http://www.w3.org/TR/html401/struct/global.html#h-7.3

You can set properties on the html element if you like, but that's not common. 如果您愿意,可以在html元素上设置属性,但这并不常见。 It's normally simpler to set properties on the body . body上设置属性通常更简单。

There's nothing illogical in setting margin on html . html上设置margin没有什么不合逻辑的。 The margin is outside the box of the element and need not appear inside the box of any other element. 边距位于元素框之外,不需要出现在任何其他元素的框内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM