html - 绝对位置与边距底部。添加间隔 div 不起作用
问题描述
我有一个 div,里面有一些元素。然后我在它下面有一个绝对 div(我将它推到页面顶部)。我想将 margin-bottom 添加到绝对 div 中。
但是要求是:我不想将margin-top 添加到“container-fluid” div。绝对 div 应该保持绝对。
我尝试添加一个间隔 div,但没有奏效(它应该有效,但它没有)。感谢所有帮助:)
演示:
#container-test {
position: absolute;
background-color: #ffffff;
top: 0;
left: 0;
width: 100%;
height: 65px;
margin-bottom: 500px;
}
.spacer {
height: 50px;
margin: 0 0 -50px 0;
/* margin: 20px 0 -50px 0; use this if you want #container to have a 'bottom padding', in this case of 20px */
background: transparent;
/* you'll need this if #container's parent element has a different background from #container itself */
}
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="./example.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h1>Hello World!</h1>
<p>Resize the browser window to see the effect.</p>
<p>The columns will automatically stack on top of each other when the screen is less than 768px wide.</p>
<div class="row">
<div class="col-sm-4">
<h3>Title 1 - col-sm-4</h3>
</div>
<div class="col-sm-4" style="background-color:lavenderblush;">
<div class="section-topleft">
<h3>Title 1 - col-sm-4</h3>
</div>
<h3>Title 2 - col-sm-4</h3>
</div>
<div class="col-sm-4" style="background-color:lavender;">
<h3>Title 3 - col-sm-4</h3>
</div>
</div>
</div>
<div id='container-test'>
<div class="spacer"></div>
<p>This text should have a margin-bottom to push the other elements down.</p>
</div>
</body>
解决方案
推荐阅读
- dataset - 如何创建没有标签的 TensorFlow 数据集?'ReadFile' Op 的输入'filename' 的 float32 类型与预期的字符串类型不匹配
- azure - Azure DevOps 主体未显示在 Key Vault 中
- java - 将 int 数组中的数字更改为字母并在 java 中返回 String
- css - SCSS:警报组件 - 根据背景颜色更改 SVG 颜色?
- swift - 无法在 Carplay 音乐上显示专辑封面
- laravel - Laravel 背包 select2_from_ajax 在保存正确值后将我的值设置为 null
- sql - JSON_VALUE 值返回 NULL 而不是实际值
- ios - 如何在停用音频会话后恢复其他应用程序的音频播放以及如何在不混合的情况下在后台开始音频播放?
- excel - 如何使用 VBA 打印同一张纸的多次迭代
- python - 为什么这个索引函数显示的是 2 而不是 4?