絕對定位影響問題
<style type="text/css">
*{
margin: 0px;padding:0px;
}
.wrap{
background:#ccc;height:160px;
}
.box1{
background:red;height:60px;
.box2{
background:blue;height:50px;
}
.box3{
background:green;height:40px;position: absolute;top:40px;left: 50px;
}
</style>
</head>
<body>
<div class="wrap">
<div class="box1">box1</div>
<div class="box2">box2</div>
<div class="box3">box3box3box3</div>
</div>
</body>
</html>
請問這個代碼為什么box2 和box1 css樣式都顯示不出來,我把box2 和box1 都設置成相對定位,又可以,請問這是為什么?,因為絕對定位對兄弟元素也有影響嗎?
2017-05-26
.box1少了一個括號,還有注意代碼書寫格式,CSS樣式不要寫在一行,不利于排查BUG,也不利于別人理解你的代碼