I have an element with height, padding, and overflow:hidden. Its child element respects the top and side paddings, but it overlaps into the parent's padding-bottom. How do I prevent this?
#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>
Edit: in response to the suggestion that this is the same as overflow:hidden ignoring bottom padding , it's not. The final answer to my question is so much more elegant than any of the answers to that other question because my setup is different: I only have one child element.
Add one parent div like this
<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>
Add this css
.test{
width:100px;
padding:25px;
background:yellow;
}
#parent{
height:100px;
overflow:auto;
}
You should use like this -
#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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.