gpt4 book ai didi

html - 当我为 body 标签使用 100% 宽度时,我如何知道使用了多少像素

转载 作者:行者123 更新时间:2023-11-28 15:56:57 25 4
gpt4 key购买 nike

我正在尝试制作一个布局流畅的网站。因此,为此我尝试使用百分比作为衡量标准。如果我没记错的话,百分比是根据父元素计算的。由于html标签没有任何设置宽度,body标签如何计算100%宽度? 100% 是否意味着您正在查看页面的屏幕的全分辨率?

谢谢

最佳答案

你必须 read the specs找到问题的答案:

https://www.w3.org/TR/CSS22/visudet.html#x3说到百分比宽度:

<percentage>Specifies a percentage width. The percentage iscalculated with respect to the width of the generated box's containingblock.

关于包含 block :

https://www.w3.org/TR/CSS22/visudet.html#containing-block-details说:

The position and size of an element's box(es) are sometimes calculatedrelative to a certain rectangle, called the containing block of theelement. The containing block of an element is defined as follows:

The containing block in which the root element lives is a rectanglecalled the initial containing block. For continuous media, it has thedimensions of the viewport and is anchored at the canvas origin;

(...)

根元素是 ( https://www.w3.org/TR/html-markup/html.html )。

屏幕被认为是连续媒体

视口(viewport) Canvas 的关系很简单:

https://www.w3.org/TR/CSS22/visuren.html#viewport https://www.w3.org/TR/CSS22/intro.html#canvas

User agents for continuous media generally offer users a viewport (awindow or other viewing area on the screen) through which usersconsult a document. User agents may change the document's layout whenthe viewport is resized (see the initial containing block).

When the viewport is smaller than the area of the canvas on which thedocument is rendered, the user agent should offer a scrollingmechanism.

因此,为了简化这一点, Canvas 大小会考虑内容大小,即使它不适合浏览器窗口也是如此。

浏览器窗口包含视口(viewport)(不考虑菜单、滚动条和状态栏)。


所以,如果 <body>宽度为 100%,这意味着它与 <html> 的宽度相同元素,其宽度等于视口(viewport)的宽度。

您可以通过检查 <html> 的 css 轻松找到视口(viewport)宽度Chrome 上的元素。

关于html - 当我为 body 标签使用 100% 宽度时,我如何知道使用了多少像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40942006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com