I am not sure how to look for this information online, so I want to ask here.
I want to have the nav bar display fully on full-screen media query but in a hamburger when phone width.
Any direction would be appreciated.
Advertisement
Answer
Heres one example https://codepen.io/alvarotrigo/pen/MWEJEWG
JavaScript
x
153
153
1
<meta name="viewport" content="width=device-width, initial-scale=1">
2
<section class="top-nav">
3
<div>
4
Logo Here
5
</div>
6
<input id="menu-toggle" type="checkbox" />
7
<label class='menu-button-container' for="menu-toggle">
8
<div class='menu-button'></div>
9
</label>
10
<ul class="menu">
11
<li>One</li>
12
<li>Two</li>
13
<li>Three</li>
14
<li>Four</li>
15
<li>Five</li>
16
</ul>
17
</section>
18
19
<h2>Resize window to collapse menu</h2>
20
21
@import url(https://fonts.googleapis.com/css?family=Raleway);
22
h2 {
23
vertical-align: center;
24
text-align: center;
25
}
26
27
html, body {
28
margin: 0;
29
height: 100%;
30
}
31
32
* {
33
font-family: "Raleway";
34
box-sizing: border-box;
35
}
36
37
.top-nav {
38
display: flex;
39
flex-direction: row;
40
align-items: center;
41
justify-content: space-between;
42
background-color: #00BAF0;
43
background: linear-gradient(to left, #f46b45, #eea849);
44
/* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
45
color: #FFF;
46
height: 50px;
47
padding: 1em;
48
}
49
50
.menu {
51
display: flex;
52
flex-direction: row;
53
list-style-type: none;
54
margin: 0;
55
padding: 0;
56
}
57
58
.menu > li {
59
margin: 0 1rem;
60
overflow: hidden;
61
}
62
63
.menu-button-container {
64
display: none;
65
height: 100%;
66
width: 30px;
67
cursor: pointer;
68
flex-direction: column;
69
justify-content: center;
70
align-items: center;
71
}
72
73
#menu-toggle {
74
display: none;
75
}
76
77
.menu-button,
78
.menu-button::before,
79
.menu-button::after {
80
display: block;
81
background-color: #fff;
82
position: absolute;
83
height: 4px;
84
width: 30px;
85
transition: transform 400ms cubic-bezier(0.23, 1, 0.32, 1);
86
border-radius: 2px;
87
}
88
89
.menu-button::before {
90
content: '';
91
margin-top: -8px;
92
}
93
94
.menu-button::after {
95
content: '';
96
margin-top: 8px;
97
}
98
99
#menu-toggle:checked + .menu-button-container .menu-button::before {
100
margin-top: 0px;
101
transform: rotate(405deg);
102
}
103
104
#menu-toggle:checked + .menu-button-container .menu-button {
105
background: rgba(255, 255, 255, 0);
106
}
107
108
#menu-toggle:checked + .menu-button-container .menu-button::after {
109
margin-top: 0px;
110
transform: rotate(-405deg);
111
}
112
113
@media (max-width: 700px) {
114
.menu-button-container {
115
display: flex;
116
}
117
.menu {
118
position: absolute;
119
top: 0;
120
margin-top: 50px;
121
left: 0;
122
flex-direction: column;
123
width: 100%;
124
justify-content: center;
125
align-items: center;
126
}
127
#menu-toggle ~ .menu li {
128
height: 0;
129
margin: 0;
130
padding: 0;
131
border: 0;
132
transition: height 400ms cubic-bezier(0.23, 1, 0.32, 1);
133
}
134
#menu-toggle:checked ~ .menu li {
135
border: 1px solid #333;
136
height: 2.5em;
137
padding: 0.5em;
138
transition: height 400ms cubic-bezier(0.23, 1, 0.32, 1);
139
}
140
.menu > li {
141
display: flex;
142
justify-content: center;
143
margin: 0;
144
padding: 0.5em 0;
145
width: 100%;
146
color: white;
147
background-color: #222;
148
}
149
.menu > li:not(:last-child) {
150
border-bottom: 1px solid #444;
151
}
152
}
153