Navigation

Home About Contact Gallery
HTML, CSS and JavaScript Code (Navigation)

HTML Code

<div class="topnav" id="myTopnav">
<a href="#"
class="active marginhome">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
<a href="#">Gallery</a>
<a href="javascript:void(0);"
class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>

CSS Code

.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #04AA6D;
color: white;
}
.marginhome{
margin-left: 500px;
}
.topnav .icon {
display: none;
}
@media screen and (max-width: 1150px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 1150px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
@media screen and (max-width: 1150px) {
.marginhome {
margin-left: 0px;
}
}

JavaScript Code

<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>