【发布时间】:2017-07-23 10:14:30
【问题描述】:
我有 2 个 div 元素,我想将第二个元素的一部分放在第一个元素的顶部,因为我给出了相对于第二个元素和底部 50px 的位置。但是我在第二个元素之后放置了另一个 div,我在两者之间获得了一些空间。如何避开那个空间。
这是我的代码示例
<!DOCTYPE html>
<html lang="en">
<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.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div style="height:100px;background-color:red;"></div>
<div style="height:100px;background-color:green;width:250px;margin:0 auto;position:relative;bottom:50px;"></div>
<p style="text-align:center;">Hello am here</p>
</div>
</body>
</html>
https://www.w3schools.com/code/tryit.asp?filename=FHRQQ7D92JKP
【问题讨论】: