1<!DOCTYPE html>
2<html>
3<head>
4<meta name="viewport" content="width=device-width, initial-scale=1">
5<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
6<style>
7body {
8 margin: 0;
9 font-family: Arial, Helvetica, sans-serif;
10}
11
12.topnav {
13 overflow: hidden;
14 background-color: #333;
15}
16
17.topnav a {
18 float: left;
19 display: block;
20 color: #f2f2f2;
21 text-align: center;
22 padding: 14px 16px;
23 text-decoration: none;
24 font-size: 17px;
25}
26
27.topnav a:hover {
28 background-color: #ddd;
29 color: black;
30}
31
32.topnav a.active {
33 background-color: #4CAF50;
34 color: white;
35}
36
37.topnav .icon {
38 display: none;
39}
40
41@media screen and (max-width: 600px) {
42 .topnav a:not(:first-child) {display: none;}
43 .topnav a.icon {
44 float: right;
45 display: block;
46 }
47}
48
49@media screen and (max-width: 600px) {
50 .topnav.responsive {position: relative;}
51 .topnav.responsive .icon {
52 position: absolute;
53 right: 0;
54 top: 0;
55 }
56 .topnav.responsive a {
57 float: none;
58 display: block;
59 text-align: left;
60 }
61}
62</style>
63</head>
64<body>
65
66<div class="topnav" id="myTopnav">
67 <a href="#home" class="active">Home</a>
68 <a href="#news">News</a>
69 <a href="#contact">Contact</a>
70 <a href="#about">About</a>
71 <a href="javascript:void(0);" class="icon" onclick="myFunction()">
72 <i class="fa fa-bars"></i>
73 </a>
74</div>
75
76<div style="padding-left:16px">
77 <h2>Responsive Topnav Example</h2>
78 <p>Resize the browser window to see how it works.</p>
79</div>
80
81<script>
82function myFunction() {
83 var x = document.getElementById("myTopnav");
84 if (x.className === "topnav") {
85 x.className += " responsive";
86 } else {
87 x.className = "topnav";
88 }
89}
90</script>
91
92</body>
93</html>
94