I have been long away from HTML and CSS, can't find the solution to this simple problem.
I have one div inside the other. Outer Black and inner orange.
My HTML and CSS is :
#outer {
position: fixed;
width: 30%;
height: 30%;
background-color: black;
}
#inner {
width: 100%;
height: 100%;
margin: 5px;
background-color: orange;
}
<div id="outer">
<div id="inner">
</div>
</div>
Why is my inner DIV spilling out of the outer ? How do I fix it without giving fixed dimensions?
The outer div has a width and height of 100%, the content div in which all of this is placed, on the other hand, has a width of some 770px. Maybe it has to do with that?
As you can see, its too big for the DIV, and so pushes outside it (this is the same for both Firefox and IE). This is a relevant example bit of HTML:
The DIV displays fine when there’s no image, but as soon as there is I get the following: As you can see, its too big for the DIV, and so pushes outside it (this is the same for both Firefox and IE).
Because of the margin - the width is 100% PLUS the margin. To avoid that, write width: calc(100% - 10px);
(= twice the margin.) Same for height.
#outer {
position: fixed;
width: 30%;
height: 30%;
background-color: black;
}
#inner {
width: calc(100% - 10px);
height: calc(100% - 10px);
margin: 5px;
background-color: orange;
}
<div id="outer">
<div id="inner">
</div>
</div>
The answers above assume that you do not want the margin. If you, in fact, want the margins, then you can add overflow: hidden;
to the #outer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With