I have a div with a specific width
and height
in pixels. I have another div inside it which takes 100%
of both the width
and height
of the outer div. When I don't have position: fixed
on the inside div, it takes the correct (100%
) width
of the outer div. However, when I set position: fixed
to it, the div goes beyond the outside div boundaries. I am not sure why.
Code:
#outer-div {
width: 800px;
height: 300px;
}
#inner-div {
width: 100%;
height: 100%;
border: 1px solid black;
display: flex;
align-items: center;
justify-content: center;
position: fixed;
}
#bottom-div {
position: absolute;
top: 2000px;
}
<div id="outer-div">
<div id="inner-div">This is some text</div>
</div>
<div id="bottom-div">I am at the bottom to allow page to scroll.</div>