2015-10-16 84 views
1

我有一個元素,高度,填充和溢出:隱藏。它的子元素尊重頂部和側面的填充,但是它與父母的填充底部重疊。我如何防止這種情況?CSS:獲取子元素,以尊重父母的填充底部

http://jsfiddle.net/va78jsm5/

#parent{ 
    background:yellow; 
    overflow:hidden; 
    width:100px; 
    height:100px; 
    padding:25px; 
} 

<div id = "parent"> 
    <div id = "child"> 
     text text text text text text ... 
    </div> 
</div> 

編輯:響應的建議,這是一樣的overflow:hidden ignoring bottom padding,事實並非如此。我的問題的最終答案比任何其他問題的答案都要優雅得多,因爲我的設置不同:我只有一個子元素。

+4

[溢出:隱藏忽略底部填充]的可能的複製(http://stackoverflow.com/questions/8981811/overflowhidden-ignoring-bottom-padding)母體的 – Steven

+0

刪除高度。 – Tushar

回答

0

您可以將heightoverflow添加到#child

Jsfiddle

#child{ 
    height: 100%; 
    overflow: hidden; 
} 
+0

完美,謝謝! – user984003

0

添加一個父DIV這樣

<div class="test"> 
<div id = "parent"> 
    <div id = "child"> 
     text text text text text text text text text text text text text text text text text text text text text text text text 
    </div> 
</div> 
</div> 

添加這個CSS

.test{ 
    width:100px; 
    padding:25px; 
    background:yellow; 
} 
#parent{ 
    height:100px; 
    overflow:auto; 

} 
0

你應該使用這樣 -

#child { 
    height: 100%; 
    overflow: hidden; 
} 

#parent{ 
 
    background:yellow; 
 
    overflow:hidden; 
 
    width:100px; 
 
    height:100px; 
 
    padding:25px; 
 
} 
 

 
#child { 
 
    height: 100%; 
 
    overflow: hidden; 
 
}
<div id = "parent"> 
 
    <div id = "child"> 
 
     text text text text text text text text text text text text text text text text text text text text text text text text 
 
    </div> 
 
</div> 
 

 
<br/> 
 
<div> 
 
    There should also be padding on the bottom of the yellow square. 
 
</div>