<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>title</title>
<style?type="text/css">
div{border:1px?red?solid;}
#box1{
????width:400px;
????height:400px;??????????
}
#box2{
????float:right;
}
#box3{
????position:absolute;
}
</style>
</head>
<body>
<div?id="box1">
????<div?id="box2">
?????????<div?id="box3">
??????????????相對參照元素進行定位
?????????</div>
????</div>
</div>
</body>
</html>代碼如上顯示,運行后子元素會跑到包含塊兒外面(如圖所示),這不符合我對float的理解,不過我發現如果對box2的div設置width值,子元素就不會跑出去了,我不知道應該如何解釋這個現象,有沒有大神可以解答,謝謝。
最近使用float發現一個子元素超出包含塊的情況,不知道如何解釋
Robert_Langdon
2017-01-02 23:01:18