2015-10-16 75 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>