无解 ( 直接在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