gpt4 book ai didi

html - Bootstrap 3 列内的相对 div 不受尊重

转载 作者:行者123 更新时间:2023-11-28 17:27:36 25 4
gpt4 key购买 nike

对于 Bootstrap 3 内的 relative div,我有一个奇怪的行为柱子。我的标记是:

<div class="col-lg-6">
<div class="large" style="background: url(img/bg.jpg);">
<h1 class="grid-header">Content 1</h1>
</div>
</div>

.large {
height: 963px;
background: grey;
margin: 15px 0px;
position: relative;
}

.grid-header {
font-size: 48px;
color: #FFFFFF;
margin: 22px 0 0 22px;
}

我不知道为什么,.grid-headermargin.large 中不起作用。它的所有边距都适用于主体,而不适用于其父元素。

有什么我不记得的会影响 Bootstrap 列内的相对布局。

谢谢

最佳答案

此问题称为 margin-collpasing

Top and bottom margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the margins combined into it, a behavior known as margin collapsing.

在这种情况下, parent 和第一个 child

Parent and first/last child

If there is no border, padding, inline content, or clearance to separate the margin-top of a block with the margin-top of its first child block, or no border, padding, inline content, height, min-height, or max-height to separate the margin-bottom of a block with the margin-bottom of its last child, then those margins collapse. The collapsed margin ends up outside the parent.

所以你可以通过添加这个来修复它:

.large {
padding-top:1px;
}

检查这个BootplyDemo

关于html - Bootstrap 3 列内的相对 div 不受尊重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26844115/

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