【问题标题】:I am facing issue with positioning of one element over another using html and css我面临使用 html 和 css 将一个元素定位在另一个元素上的问题
【发布时间】: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

【问题讨论】:

    标签: html css


    【解决方案1】:

    删除 position:relative;bottom:50px 并替换为 margin:-50px auto 0;
    如果有效,请告诉我。
    干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      相关资源
      最近更新 更多