2 KiB
2 KiB
navbar - classic
for making navbar first we must add html elements to file
<div class="topnav">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
font and margin
we can specify what font family we want and we add margin: 0;
so that default browser margin go away
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
background color and overflow
now we set background for our nav, also we add overflow: hidden;
so content form next to navbar dose not come to navbar area
.topnav {
background-color: #333;
overflow: hidden;
}
styling link elements
now we need to style <a>
elements
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
float: left;
make our element float to left we can also make it float to right withfloat:rigt;
color
make color of our text what we wanttext-align: center;
make text centered in their container between the paddingpadding: 14px 16px;
make container for our text so it can sit in ittext-decoration: none;
remove the blue text color and under linefont-size:
we tell browse how big our font must be
styling the hover
we can specify what CSS we have when we hover with mouse on element in here a elements here we make color white and text black
.topnav a:hover {
background-color: #ddd;
color: black;
}
styling one of elements
we can also change some of elements with adding a class to them and then styling
adding class
<a class="active" href="#home">Home</a>
styling
.topnav a.active {
background-color: #04AA6D;
color: white;
}