为什么<p>标签的 margin 和其他块级标签的 margin,上下边距会重叠计算,但和<video>的 margin 却不会重叠计算?

2019-08-06 11:57:54 +08:00
 lisisi

例 1:

<p style="margin: 10px 0">this is paragraph</p>
<h1 style="margin: 10px 0">This is heading 1</h1>

例 2:

<p style="margin: 10px 0">this is paragraph</p>
<video style="margin: 10px 0" src="#">This is video</video>

例 1 中,p 和 h1 之间的总 margin 实际是 10px ( p 的 margin-bottom 和 h1 的 margin-top 重叠计算了);
例 2 中,p 和 video 之间的总 margin 实际是 20px ( p 的 margin-bottom 和 video 的 margin-top 没有重叠计算)。

3558 次点击
所在节点    CSS
2 条回复
suinia
2019-08-06 12:02:40 +08:00
margin 重叠 只发生在 block 元素上, 只发生在垂直方向上
meepo3927
2019-08-06 18:01:08 +08:00
<video /> 默认不是块级元素

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/589454

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX