“自动”到底是什么? CSS height 属性的值平均值?

发布于 12-12 10:59 字数 166 浏览 1 评论 0原文

w3schools 表示对于身高

auto :浏览器计算高度。这是默认的

但是“浏览器计算高度”是什么意思?这是否意味着它只是简单地总结所包含元素的高度?对于所有浏览器来说,这总是用相同的方法计算吗?

w3schools says that for height:

auto : The browser calculates the height. This is default

But what does “browser calculates the height” mean? Does it mean it just simply sums up the contained elements’ heights? Is this always calculated with the same method for all browser?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光清浅2024-12-19 10:59:10

浏览器计算高度是什么意思?

这意味着浏览器将使元素的高度足以适应其内容。

这是否意味着它只是简单地总结所包含元素的高度(如果它们彼此重叠)?

不,事情比这更复杂,但我确信这是其中的一部分。

对于所有浏览器,这总是使用相同的方法计算吗?

不,通常会有很小的差异。如果您打算根据元素的高度执行计算,则应该在 JavaScript 中计算该元素的高度,不要假设它在所有浏览器上都具有相同的高度。

What does it mean browser calculates the height?

It means the browser will make the element's height sufficient to fit its content.

Does it mean it just simply sums up the contained elements heights if they are up on each other?

Nope, it is more complicated than that, but I'm sure that is part of it.

Is this always calculated with the same method for all browsers?

No, there are generally small variances. You should calculate the element's height in JavaScript if you intend to perform calculations based on it, don't assume it will have the same height on all browsers.

你曾走过我的故事2024-12-19 10:59:10

CSS 2.1 规范和 CSS3 基本框模型规范有关于浏览器应如何计算高度的部分:

我发现将它们转化为实际应该发生的事情有点困难,而且我不能说浏览器是否真的遵循这些描述。

The CSS 2.1 spec, and the CSS3 Basic Box model spec, have sections on how browsers should calculate heights:

I find it a bit difficult to translate them into what should actually happen though, and I couldn’t say if browsers actually follow these descriptions.

酒儿2024-12-19 10:59:10

它总结为:所包含的元素,加上填充、边框和边距。
所有浏览器中求和的方法应该是相同的,但元素的大小不同。

It summs up: the contained elements, plus the paddings, border and margins.
The method for summing should be the same in all browsers, but the size of elements differ.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文