1<!-- How to create a navigation bar:
2 This is the html file:
3
4 Put the class="active" in the html file/page you are coding in
5 (e.g. put the class="active" in the Home.html file)
6 To position a page link to the right do class="right"
7-->
8<body>
9<ul class="topnav">
10 <li><a class="active" href="Home.html">Home</a></li>
11 <li><a href="Page1.html">Page1</a></li>
12 <li><a href="Page2.html">Page2</a></li>
13 <li class="right" ><a href="About.html">About</a></li>
14</ul>
15</body>
16
17<!-- This is the css file:
18 (have a play with the colours and features!)-->
19ul.topnav {
20 list-style-type: none;
21 margin: 0;
22 padding: 0;
23 overflow: hidden;
24 background-color: #333;
25 font-family: arial;
26 text-align: left;
27 width: 100%;
28 position: sticky;
29 top: 0;
30}
31ul.topnav li {float: left;}
32ul.topnav li a {
33 display: block;
34 color: white;
35 text-align: center;
36 padding: 14px 16px;
37 text-decoration: none;
38 float: left;
39 font-size: 17px;
40 border-right: 1px solid #bbb;
41}
42ul.topnav li a:hover:not(.active) {
43 background-color: #ddd;
44 color: black;
45}
46ul.topnav li a.active {
47 background-color: #4CAF50;
48}
49ul.topnav li.right {
50 float: right;
51}
52@media screen and (max-width: 720px) {
53 ul.topnav li{
54 width: 100%;
55 }
56 ul.topnav a{
57 width: 100%;
58 }
59}
60<!-- END -->
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <title>Navbar</title>
6
7<style>
8body {
9margin: 0;
10}
11.navbar{
12padding: 15px;
13background-color: grey;
14display: flex;
15justify-content: space-between;
16font-size: 30px;
17text-decoration: none;
18color: #fff;
19}
20 .nav-item {
21 margin: 0;
22 padding: 0;
23 flex: 1;
24 max-width: 50%;
25 display: flex;
26 justify-content: space-evenly;
27 font-size: 25px;
28 }
29 .nav-link {
30 display: inline-block;
31 }
32 a{
33 text-decoration: none;
34 color: #fff;
35 }
36
37 @media (max-width: 715px) {
38 .nav-item {
39 flex-direction: column;
40 align-items: center;
41 }
42 .nav-link {
43 margin: 5px 0;
44 }
45 }
46</style>
47
48
49</head>
50<body>
51<nav class="navbar">
52 <a class="brand" href="">Navebar</a>
53 <ul class="nav-item">
54 <li class="nav-link"><a href="">Learn more</a></li>
55 <li class="nav-link"><a href="">About</a></li>
56 <li class="nav-link"><a href="">Contact</a></li>
57 </ul>
58 <a class="home" href="">Home</a>
59</nav>
60</body>
61</html>
1/* This is the css for the nav bar*/
2
3nav{
4
5 display: flex;
6 align-items: center;
7 position: sticky;
8 top: 0px;
9 align-items: center;
10 min-height: 8vh;
11
12}
13
14nav::before{
15 content: "";
16 background-color: rgb(255, 255, 255);
17 position: absolute;
18 top:0px;
19 left:0px;
20 height: 100%;
21 width:100%;
22 z-index: -1;
23 opacity: 0.4;
24}
25
26
27#logo{
28 color:rgb(0, 0, 0);
29 text-transform: uppercase;
30 letter-spacing: 5px;
31 margin-left: 20px;
32 margin-right: 60px;
33 font-size: 22px;
34}
35
36.nav-links{
37 display: flex;
38 justify-content: space-around;
39 width: 18%;
40}
41.nav-links li{
42 list-style: none;
43 display: inline-block;
44
45}
46
47#N1{
48 margin-left: 20px;
49 margin-right: 10px;
50}
51#N2{
52 padding-left: 5px;
53}
54
55.nav-links a{
56 color:rgb(0, 0, 0);
57 font-size: 20px;
58 text-decoration: none;
59 letter-spacing: 3px;
60 font-weight: bold;
61 width: 150px;
62 display: inline-block;
63 text-align: center;
64
65}
66
67.cool-link::after{
68 content: '';
69 display: block;
70 width: 0;
71 height: 2px;
72 background: rgb(0, 0, 0);
73 transition: width .3s;
74}
75.cool-link:hover::after{
76 width:100%;
77 transition:width .3s;
78}
79/* designing of the buttons */
80.btn{
81 border: 1px solid #3498db;
82 background: none;
83 padding: 10px 20px;
84 font-size: 25px;
85 font-family: "montserrat";
86 cursor: pointer;
87 margin: 10px;
88 transition: 0.8s;
89 position: relative;
90 overflow: hidden;
91 text-decoration: none;
92 }
93 .btn::before{
94 content: "";
95 position: absolute;
96 left: 0;
97 width: 100%;
98 height: 0%;
99 background: #3498db;
100 z-index: -1;
101 transition: 0.8s;
102
103 }
104 .btn a{
105 text-decoration: none;
106 color:#fff;
107
108 }
109 .btn4{
110 color: #fff;
111
112 }
113
114 .btn4:hover{
115 color:black ; /* change the color*/
116 }
117
118
119 .btn4::before{
120 bottom: 0;
121 border-radius: 50% 50% 0 0;
122 }
123 .btn4::before{
124 height: 180%;
125 }
126
127 .btn4:hover::before{
128 height: 0%;
129 }
130
131
132/* button ends */
133
134.burger{
135 position: absolute;
136 right: 30px;
137 cursor: pointer;
138 display: none;
139}
140.burger div{
141 width: 25px;
142 height: 3px;
143 background-color: rgb(5, 5, 5);
144 margin: 5px;
145}
146
147
148/* Nav bar in the mobile version*/
149
150@media screen and (max-width: 670px)
151{
152 body{
153 overflow-x: hidden;
154 }
155
156 .nav-links{
157 position: absolute;
158 right: 0px;
159 height: 25vh;
160 top: 8vh;
161 background-color: rgb(241, 241, 241);
162
163
164 display: flex;
165 flex-direction: column;
166 align-items: center;
167 width: 50%;
168 transform: translateX(100%);
169 transition: transform 0.3s ease-in;
170 /* canging the z index of the */
171
172 }
173
174 .nav-links a{
175 color:rgb(0, 0, 0);
176 font-size: 20px;
177 text-decoration: none;
178 letter-spacing: 3px;
179 font-weight: bold;
180
181 display: inline-block;
182 width: 150px;
183 text-align: center;
184 margin-left: 50px;
185 }
186
187 .nav-active{
188 transform: translateX(0%);
189 }
190 .burger{
191 display: block;
192 }
193
194}
1<!DOCTYPE html>
2<html lang="en">
3
4<head>
5 <meta charset="UTF-8">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <meta http-equiv="X-UA-Compatible" content="ie=edge">
8 <title>Navigation</title>
9 <style>
10 .navbar{
11 background-color: black;
12 border-radius: 30px;
13
14 }
15 .navbar ul{
16 overflow: auto;
17 }
18 .navbar li{
19 float:left;
20 list-style: none;
21 margin: 13px 20px;
22
23 }
24 .navbar li a{
25 padding: 3px 3px;
26 text-decoration: none;
27 color: white;
28 }
29 .navbar li a:hover{
30 color: red
31 }
32 .search{
33 float: right;
34 color: white;
35 padding: 12px 75px;
36 }
37 .navbar input{
38 border: 2px solid black;
39 border-radius: 14px;
40 padding: 3px 17px;
41 width: 129px;
42 }
43 </style>
44</head>
45
46<body>
47 <header>
48 <nav class="navbar">
49 <ul>
50 <li><a href="#">Home</a></li>
51 <li><a href="#">About</a></li>
52 <li><a href="#">Services</a></li>
53 <li><a href="#">Contact us</a></li>
54 <div class="search">
55 <input type="text" name="search" id="search" placeholder="Search this website">
56 </div>
57 </ul>
58 </nav>
59 </header>
60</body>
61
62</html>
63
1<!-- HTML PART -->
2<a class="active" href="#home">Home</a>
3<a href="news.html">News</a>
4<a href="contact.html">Contact</a><a href="about.html">About</a>
5
6
7<!-- CSS PART -->
8
9.topnav a {
10 float: left;
11 color: goldenrod;
12 text-align: center;
13 padding: 14px 16px;
14 text-decoration: none;
15 font-size: 20px;
16 }
17
18 /* Change the color of links on hover */
19 .topnav a:hover {
20 background-color: rgb(221, 221, 221);
21 color: black;
22 }
23
24 /* Add a color to the active/current link */
25 .topnav a.active {
26 background-color: red;
27 color: goldenrod;
28 }