-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavbar with dropdown.html
176 lines (153 loc) · 4.35 KB
/
navbar with dropdown.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="header" id="myHeader">
<a class="navtitle" href="index.php"><h2>JLSkyzer's web</h2></a>
<div class="navbar">
<a class="basicbtn" href="index.php">Home</a>
<div class="dropdown">
<button class="dropbtn">Tuto
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Mcreator</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Resources
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Mcreator</a>
<a href="#">HTML / CSS</a>
</div>
</div>
</div>
<style>
.header {
/* background: #555; */
margin-left: auto;
margin-right: auto;
width: 99.35%;
padding: 5px;
color: #f1f1f1;
min-height: 50px;
height: auto;
background-color: #333;
/* vertical align content */
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
}
/* Page content */
.content {
padding: 16px;
}
/* The sticky class is added to the header with JS when it reaches its scroll position */
.sticky {
position: fixed;
top: 0;
width: 100%
}
/* Add some top padding to the page content to prevent sudden quick movement (as the header gets a new position at the top of the page (position:fixed and top:0) */
.sticky + .content {
padding-top: 102px;
}
.navbar{
display: flex;
flex-direction: row;
height: 50px;
min-width: 300px;
width: auto;
}
.navbar a{
display: block;
width: 100px;
line-height: 50px;
text-decoration: none;
color: white;
text-align: center;
}
.navbar .basicbtn{
background-color: rgb(78, 150, 7);
}
.navbar a:hover{
transition: 0.2s;
background-color: #f1f1f1;
color: black;
}
/* Dropdown menu */
.dropdown {
float: left;
overflow: hidden;
line-height: 50px;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 120px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 0px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
.navtitle{
text-decoration: none;
color: white;
}
</style>
<script>
// When the user scrolls the page, execute myFunction
window.onscroll = function() {myFunction()};
// Get the header
var header = document.getElementById("myHeader");
// Get the offset position of the navbar
var sticky = header.offsetTop;
// Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
// Get the offset position of the navbar
var sticky = header.offsetTop;
</script>
</body>
</html>