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<!--Method 1: Using HTML5 Nav Tag-->
2<nav>
3 Thing1 |
4 Thing2 |
5 Thing3
6</nav>
7
8<!--Method 2: HTML5 + CSS3 with DIV element-->
9
10<ul class="topnav">
11 <li><a class="active" href="#">Thing 1</a></li>
12 <li><a href="#">Page 1</a></li>
13 <li><a href="#">Page 2</a></li>
14 <li class="right" ><a href="#">Thing 2</a></li>
15</ul>
16<style>
17
18 ul.topnav {
19 list-style-type: none;
20 margin: 0;
21 padding: 0;
22 overflow: hidden;
23 background-color: #333;
24 font-family: arial;
25 text-align: left;
26 width: 100%;
27 position: sticky;
28 top: 0;
29 }
30 ul.topnav li {float: left;}
31 ul.topnav li a {
32 display: block;
33 color: white;
34 text-align: center;
35 padding: 14px 16px;
36 text-decoration: none;
37 float: left;
38 font-size: 17px;
39 border-right: 1px solid #bbb;
40 }
41 ul.topnav li a:hover:not(.active) {
42 background-color: #ddd;
43 color: black;
44 }
45 ul.topnav li a.active {
46 background-color: #4CAF50;
47 }
48 ul.topnav li.right {
49 float: right;
50 }
51 @media screen and (max-width: 720px) {
52 ul.topnav li{
53 width: 100%;
54 }
55 ul.topnav a{
56 width: 100%;
57 }
58 }
59</style>