Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我面临着使用html和css将一个元素定位在另一个元素上的问题_Html_Css - Fatal编程技术网

我面临着使用html和css将一个元素定位在另一个元素上的问题

我面临着使用html和css将一个元素定位在另一个元素上的问题,html,css,Html,Css,我有两个div元素,我想把第二个元素的一部分放在第一个元素的顶部,因为我给出了相对于第二个元素的位置,从底部50px开始。但我在第二个元素之后放置了另一个div,我在两者之间获得了一些空间。如何避免这个空间 这是我的代码示例 <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8">

我有两个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>

引导示例
您好,我在这里


移除
位置:相对;底部:50px
并替换为
边距:-50px自动0

如果有效,请告诉我。

干杯

移除
位置:相对;底部:50px
并替换为
边距:-50px自动0

如果有效,请告诉我。
干杯