I’m not sure what I do wrong but when I make the height of the Browser smaller the child element is not 100% height. This happens only if there are items like a href or p. In the second Picture you can see the black Background of the body though I set "Menu-Container" to 100%.
<div class="menu-container">
<div class="menu-item1">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
</div>
</div>
.menu-container {
height: 100%;
background-color: red;
color: white;
display: flex;
align-items: stretch;
width: 100%;
position: absolute;
z-index: 100;
}
.menu-item1 {
margin-left: 20px;
width: 15%;
height: 100%;
background: dodgerblue;
}
3
Answers
For the following change with respect to HTML and CSS code as given below
index.html
styles.css
Try this . It will work and black background does not comeup. Thank you.
To force the parent div to fill the background regardless of height, try using min-height on both divs and viewport height on the child div.
If you don’t want to use vh units, you can try using flexbox on the html tag.
You did not define the height nor the width of the body.
This will make it so your body occupies the full viewport. Only then, you will define the height and width of the container.
This will make it so
.menu-container
occupies 100% of theheight
andwidth
of its parent element, which is thebody
, which occupies 100% of the viewport, therefore,.menu-container
will fill the whole viewport.