絕對定位與margin-bottom
阿新 • • 發佈:2018-11-09
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>矩形圖</title>
<script src="./js/vue.min.js"></script>
</head>
<style type="text/css">
.div1{
width: 100px;height: 200px;background-color: black;position:absolute;
}
.div2{
background-color: white;position:absolute;bottom:0;
}
.div3{
width: 10px;height: 10px;background-color: red;border: 1px solid yellow;margin-bottom:10px;
}
.div4{
width: 10px;height: 100px;background-color: blue;margin-bottom:0px;/*display: none;*/
}
.div5{
width: 1000px;height : 1px;background-color: black;position: absolute;bottom: 0;
}
</style>
<body>
<div class='div1'>
<div class='div2'>
<div class='div3'></div>
<div class='div4'></div>
</div>
<div class='div5'></div >
</div>
</body>
</html>
總結:
- 當三個div在同一級時,若最後一個div絕對定位,則倒數第二個設定margin-bottom無效,所以若想第二個div的margin-bottom有效果,需要給前兩個div設一個父div ;
- div2和div5左右居中的方法是分別設定width,然後left:50%,margin-left:-width/2。
矩形沒設定display:none
矩形設定display:none