在做項目的時候遇到一個需求,有一個div要放入內容,不知道內容多少,外層div高度默認是能夠被內容撐開,但是還有一個需求就是外地div也需要一個默認高度 這裏就可以用到css的 “ min-height ” 這個屬性了
這是一個非常簡單而且好用的屬性,以前竟然忽略了
貼一下簡單的代碼
<div style="min-height: 200px; width: 200px; border: 1px solid red; height: auto; float: left; margin-right: 100px;">
<div style="height: 100px; width: 100px; background-color: blue; margin: auto;"></div>
</div>
<div style="min-height: 200px; width: 200px; border: 1px solid red; height: auto; float: left;">
<div style="height: 300px; width: 100px; background-color: blue; margin: auto;"></div>
</div>
完美地實現了想要的效果