My question is if there is a way, without using JavaScript, to cause child divs to extend to the borders of their parent, without exceeding those borders, when you cannot kn
In your example, you can't: the 5px margin
is added to the bounding box of div#two
and div#three
effectively making their width and height 100% of parent + 5px, which will overflow.
You can use padding
on the parent Element to ensure there's 5px
of space inside its border:
<style>
html, body {width:100%;height:100%;margin:0;padding:0;}
.border {border:1px solid black;}
#one {padding:5px;width:500px;height:300px;}
#two {width:100%;height:50px;}
#three {width:100px;height:100%;}
</style>
EDIT: In testing, removing the width:100%
from div#two
will actually let it work properly as div
s are block-level and will always fill their parents' widths by default. That should clear your first case if you'd like to use margin.
I had a similar problem, but in my case, I have content in my div that height-wise will exceed the boundaries of the parent div. When it does, I want it to auto-scroll. I was able to accomplish this by using
.vscrolling_container { height: 100%; overflow: auto; }
For closure, I think the answer to this question is that there is no solution. The only way to get the behavior I want is with javascript.
you could use display: inline-block;
hope it is useful.
Make sure the outermost div has the following CSS properties:
.outer {
/* ... */
height: auto;
overflow: hidden;
/* ... */
}