2017-07-21 22 views
1

我有2個div元素,我想將第二個元素的一部分放在第一個元素的頂部,以便相對於第二個元素給出位置,從底部50px。但是我在第二個元素之後放置另一個div,我在它們之間獲得了一些空間。如何避免這個空間。我面臨的問題是使用html和css將一個元素定位在另一個元素上

這裏是我的代碼示例

<!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

回答

0

刪除position:relative;bottom:50pxmargin:-50px auto 0;
更換讓我知道,如果作品。
乾杯!

相關問題