無解 ( 直接在CSS設置無解 不過有別的解決辦法用) 替代方案是設置float/margin 或者js獲取獲取子元素高度, 或者直接給父元素設置高度最簡單this
下面是爲何無解 , 翻譯在後面翻譯
Absolutely positioned elements are completely removed from the document flow, and thus their dimensions cannot alter the dimensions of their parents. If you really had to achieve this affect while keeping the children as position: absolute, you could do so with JavaScript by finding the height of the absolutely positioned children after they have rendered, and using that to set the height of the parent. Alternatively, just use float: left/float:right and margins to get the same positioning effect while keeping the children in the document flow, you can then use overflow: hidden on the parent (or any other clearfix technique) to cause its height to expand to that of its children.ip
絕對定位元素徹底從文檔流中刪除,所以它們的維度不能改變它們的父元素的維度。 若是您確實須要在保持子元素的位置(absolute)的同時實現這種效果,那麼您能夠使用JavaScript來作到這一點,方法是在絕對位置的子元素呈現以後查找它們的高度,並使用它來設置父元素的高度。 或者,只需使用float: left/float:right和margin來得到相同的定位效果,同時將子元素保留在文檔流中,而後能夠使用overflow: hidden on the parent(或任何其餘clearfix技術)來使其高度擴展到其子元素的高度。element