Create Navbar with hover effect in
HTML & CSS
Video Tutorial of Navbar with hover effect
Navbar with hover effect [Source Codes]
To Create Navbar with hover effect with HTML and CSS, follow the given steps line by line:
Create a folder. You can name this folder whatever you want, and inside this folder, create the mentioned files.
Create an index.html file. The file name must be index and its extension .html
Create a style.css file. The file name must be style and its extension .css
Once you create these files, paste the given codes into the specified files. If you don’t want to do these then scroll down and download the source code by clicking download button.
First, paste the following codes into your index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Navbar with hover effect</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<div class="container">
<h1 class="logo">onlinefindout</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">HTML & CSS</a></li>
<li><a href="#">JAVASCRIPT</a></li>
<li><a href="#">Contact US</a></li>
</ul>
</nav>
</div>
</header>
</body>
</html>
Now paste the following codes into your style.css file
body {
margin: 0;
background: #282A35;
font-family: 'Open Sans', 'Open Sans Regular', sans-serif;
}
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #FFFFFF;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
padding: 1px 0;
font-weight: 600;
font-size: 28px;
}
nav {
float: right;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
margin-left: 70px;
padding-top: 25px;
position: relative;
}
nav a {
color: #000000;
text-decoration: none;
font-size: 20px;
font-weight: 600;
text-transform: uppercase;
position: relative;
}
nav a:hover {
color: #606060;
}
nav a::before {
content: '';
display: block;
height: 5px;
background-color: #2193EE;
position: absolute;
bottom: -20px;
width: 0%;
transition: all ease-in-out 250ms;
}
nav a:hover::before {
width: 100%;
}
If you face any difficulties while creating your Navbar with hover effect or your code is not working as expected, you can download the source code files by clicking on the download button.