【发布时间】:2017-07-09 20:59:00
【问题描述】:
MDN 解释折叠边距here。
这些是它解释的基本 3 条规则:
相邻的兄弟姐妹
相邻兄弟的边距被折叠(除了后面的 兄弟姐妹需要清除过去的浮动)。
父母和第一个/最后一个孩子
如果没有边框、内边距、内联内容, block_formatting_context 创建或清除以分隔 块的边缘顶部距其第一个子块的边缘顶部,或 没有边框、填充、内联内容、高度、最小高度或最大高度 将块的 margin-bottom 与它的 margin-bottom 分开 最后一个孩子,那么这些边距就会崩溃。折叠的边距结束 在父母之外。
空块
如果没有边框、内边距、内联内容、高度或最小高度 将块的 margin-top 与其 margin-bottom 分开,然后是其顶部 并且底部边距折叠。
查询a:我需要了解以下示例中按顺序应用的3条规则。
查询b:如果对于空块元素的边距折叠,那么它作为顶部或底部边距出现吗?您可能会说它有什么不同,但是如果我使用下面示例中的轮廓,这里看起来好像它被折叠为顶部。
基本上我有 3 个 <p> 元素,其中中间一个是空的。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ex1</title>
<style>
body{
border: 1px solid black;
}
p{
margin-top: 10px;
margin-bottom: 10px;
outline: 1px solid black;
}
#empty{
margin: 20px;
}
</style>
</head>
<body>
<p>
The oldest classical Greek and Latin writing had little or no space between words, and could be written in boustrophedon (alternating directions). Over time, text direction (left to right) became standardized, and word dividers and terminal punctuation became common. The first way to divide sentences into groups was the original paragraphos, similar to an underscore at the beginning of the new group.[3] The Greek paragraphos evolved into the pilcrow (¶), which in English manuscripts in the Middle Ages can be seen inserted inline between sentences. The hedera leaf (e.g. ☙) has also been used in the same way.
</p>
<p id ='empty'></p>
<p>
The oldest classical Greek and Latin writing had little or no space between words, and could be written in boustrophedon (alternating directions). Over time, text direction (left to right) became standardized, and word dividers and terminal punctuation became common. The first way to divide sentences into groups was the original paragraphos, similar to an underscore at the beginning of the new group.[3] The Greek paragraphos evolved into the pilcrow (¶), which in English manuscripts in the Middle Ages can be seen inserted inline between sentences. The hedera leaf (e.g. ☙) has also been used in the same way.
</p>
</body>
</html>
请注意,第一段和最后一段之间的最终边距为 20 像素。
【问题讨论】:
标签: css