I have a navbar div that has a title and a nav component. When the window gets small enough I collapse the nav element so have a burger to show and hide the nav element. Without changing the position attribute of the parent navbar div it works fine, however when I make the parent navbar div sticky I can no longer see the navbar move over onto the screen. I toggle the navbarHidden and navbarVisible class on the child nav element when the burger is clicked.
JavaScript
x
35
35
1
.navbar {
2
display: flex;
3
align-items: center;
4
justify-content: space-between;
5
height: 8vh;
6
border-bottom: 1px solid rgb(220, 220, 220);
7
position: sticky;
8
top: 0;
9
background-color: white;
10
}
11
12
.navbar nav {
13
position: absolute;
14
right: 0px;
15
top: 8vh;
16
height: 92vh;
17
display: flex;
18
flex-direction: column;
19
justify-content: space-evenly;
20
padding-right: 0;
21
font-size: 30px;
22
width: 40%;
23
background-color: antiquewhite;
24
transition: transform 0.5s ease-in;
25
z-index: 1;
26
}
27
28
.navbarHidden {
29
transform: translateX(100%);
30
}
31
32
.navbarVisible {
33
transform: translateX(0);
34
}
35
The nav element still shows up when you inspect the page though.
Advertisement
Answer
I figured it out, all you had to do was change the position on the nav element to fixed instead of absolute.