So I implemented a navbar on the right side of the wrapper which I centered. I made the wrapper height automatically adjust to the amount of content in it (Since I didn’t want to give the wrapper a pixel height because it’s fixed and doesn’t change based on the amount of content)
The navbar should have the exact height of the wrapper but it’s somehow too short even though the wrapper is a direct parent to the navbar and the navbar has a 100% height. Somehow it only works when I remove the height: auto;
on the wrapper and replace it with height: 750px;
it also kinda collapses the other page by displaying too short.
This is what it looks like with #wrapper {height: 750px;}
and how it should look like:
And this is how the two pages end up looking when I set the #wrapper
height to auto
:
Here is the code for both my HTML and CSS:
body {
background: url(./nurple-static-bright.gif);
height: 100%;
width: 100%;
margin: 0;
font-family: 'VT323';}
#wrapper {
width: 800px;
height: 750px;
margin: 0 auto;
background-color: rgba(77, 77, 77, 0.558);
text-align: center;
margin-top: 20px;
border: 3px rgb(189, 189, 189) solid;
border-bottom-left-radius: 30px;
border-bottom-right-radius: 30px;}
.container { //* the container div is a parent of the wrapper *//
margin-top: 20px;}
.navbar {
height: 100%;
width: 25%;
float: right;
border-left: 3px rgb(189, 189, 189) solid;
border-bottom-right-radius: 27px;}
//* The .content container is the div of the paragraphs you see in the pictures
.content had two other divs, one containing the "Sincere Welcome" (box1) text and the other
one containing the rest paragraphs "box2 "*//
.content {
height: 100%;
width: 75%;}
.box1 {
height: min-content;
width: 100%;
border-bottom: 3px rgb(189, 189, 189) solid;
}
<body>
<div class="container">
<div class="header"></div>
<div id="wrapper">
<div class="navbar"></div>
<div class="content">
<div class="box1"></div>
<div class="box2"></div>
</div>
</div>
</div>
</body>
2
Answers
This is because
.navbar
is trying to scale based on the height of the#wrapper
, but withheight: auto;
it doesn’t have a defined height.To fix it, you can use
display: flex;
for#wrapper
and reorder the.navbar
withorder: 2;
:I have tried to fix it using
flex
on the.content
and applyingflex-grow: 1;
to the.box1
. You don’t need to set staticheight
to your.wrapper
.