html – 为什么水平边距不会像垂直边距那样崩溃?

前端之家收集整理的这篇文章主要介绍了html – 为什么水平边距不会像垂直边距那样崩溃?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我理解为什么边缘崩溃发生了.我在各种网站上看到了很少的例子,说明它是如何发生的以及为什么会发生.

具体来说,以下是我读到的帖子的链接
https://css-tricks.com/almanac/properties/m/margin/

它清楚地解释了崩溃是垂直发生的,并且它是出于某种目的而实现的.但是,它提到“这不会发生在水平边缘(左和右),只有垂直(顶部和底部).”没有解释为什么它不会发生在水平边缘上.

其他地方没有找到答案.

出于好奇,我想知道,为什么不发生水平边缘崩溃?任何帮助赞赏.

解决方法

由于管理边际崩溃的规则意味着他们永远无法满足条件,因此水平边距永远不会有崩溃的机会.

In CSS,the adjoining margins of two or more Boxes (which might or might not be siblings) can combine to form a single margin. Margins that combine this way are said to collapse,and the resulting combined margin is called a collapsed margin.

折边率(http://www.w3.org/TR/CSS21/box.html#collapsing-margins)

相邻的框只能是块级框:

Two margins are adjoining if and only if:

  • both belong to in-flow block-level Boxes that participate in the same block formatting context

折边率(http://www.w3.org/TR/CSS21/box.html#collapsing-margins)

如果它们没有浮动或绝对定位,则边距只会崩溃:

  • Margins between a floated Box and any other Box do not collapse (not even between a float and its in-flow children).
  • Margins of elements that establish new block formatting contexts (such as floats and elements with ‘overflow’ other than ‘visible’) do not collapse with their in-flow children.
  • Margins of absolutely positioned Boxes do not collapse (not even with their in-flow children).

折边率(http://www.w3.org/TR/CSS21/box.html#collapsing-margins)

这意味着块级框永远不能水平放置在同一条线上(默认情况下块级框将自动在新线上开始)并同时满足边距折叠条件.

从理论上讲,内联框可以满足条件,但由于它们不是块级,因此规则根本不适用于它们.

In an inline formatting context,Boxes are laid out horizontally,one after the other,beginning at the top of a containing block. Horizontal margins,borders,and padding are respected between these Boxes.

内联格式化上下文(http://www.w3.org/TR/CSS21/visuren.html#block-formatting)

也就是说,他们不崩溃的简单原因是W3C这么说:

Horizontal margins never collapse.

折边率(http://www.w3.org/TR/CSS21/box.html#collapsing-margins)

原文链接:https://www.f2er.com/html/227797.html

猜你在找的HTML相关文章