Reputation: 81
This is the first time I'm getting this type of problem. I'm trying to make responsive navigation bar. At a certain width, I want my nav links div to go to right side bar. But the nav links div is not taking full viewport height even after giving 100vh. Here is the code -
HTML
<header>
<nav>
<div class="logo">Logo</div>
<div class="nav-items">
<li><a href = '#'>Link-1</a></li>
<li><a href = '#'>Link-2</a></li>
<li><a href = '#'>Link-3</a></li>
</div>
</nav>
</header>
SCSS
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
header {
background: blue;
nav {
height: 65px;
max-width: 1340px;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
margin: auto;
padding: 1rem;
.logo {
font-size: 2rem;
color: black;
}
.nav-items {
li {
display: inline;
a {
color: black;
text-decoration: none;
margin-left: 2rem;
}
}
}
}
}
@media screen and (max-width: 768px) {
header nav .nav-items {
position: absolute;
right: 0;
height: 100vh;
width: 50%;
border: 1px solid black;
}
}
Link to codepen -
https://codepen.io/yell0wflash/pen/JjWGwJa
Upvotes: 0
Views: 11852
Reputation: 52
This is because your has align-items:center; change this based on media query.
@media screen and (max-width: 768px) {
header nav {
align-items:unset;
}
}
Upvotes: 2
Reputation: 19772
The height is 100vh, but you have set align-items:center
, so the element is offset to align with the other flex element.
Add
header nav {
align-items: flex-start;
}
To your media query
Now as your nav
element has padding you need to accommodate that with
height: calc(100vh - 16px);
Upvotes: 1
Reputation: 192
Set position to fixed, add top:0; also height:100vh and left or right to 0 in the media query
Upvotes: 9