HTML CSS Navigation Bar With Mouse Hover Effect

https://www.codepel.com/demo/html-css-navigation-bar-with-mouse-hover-effect/
Project: css3 Responsive menu effect
Author: Bogdan Blinnikov
Edit Online: View on CodePen
License: MIT

How to Create HTML CSS Navigation Bar With Mouse Hover Effect

Create the HTML structure as follows:

<h1>Responsive Menu Effect
hover on menu items!
</h1>

<ul class="menu">
  <li><a href="#" class="active">Home</a></li>
  <li><a href="#">About</a></li>
  <li><a href="#">Portfolio</a></li>
  <li><a href="#">Contact</a></li>
  <li class="slider"></li>
</ul>

Style using the following CSS styles:

* {
  box-sizing: border-box;
}
@font-face {
  font-family: 'PT Sans';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/ptsans/v17/jizaRExUiTo99u79D0KEwA.ttf) format('truetype');
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: 'PT Sans', Arial, Verdana;
  background-color: #eee;
}
h1 {
  text-align: center;
  font-size: 48px;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: #222;
}
.menu {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 120px;
  margin: auto;
  position: relative;
  background-color: #2c3e50;
  z-index: 7;
}
.menu li {
  float: left;
  width: 25%;
  height: 100%;
  margin: 0;
  padding: 0;
}
.menu a {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  color: #fff;
  text-decoration: none;
  position: relative;
  font-size: 18px;
  z-index: 9;
}
a.active {
  background-color: #e74c3c;
  pointer-events: none;
}
li.slider {
  width: 25%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  background-color: #e74c3c;
  z-index: 8;
  transition: left 0.4s, background-color 0.4s;
}
.menu li:nth-child(1):hover ~ .slider,
.menu li:nth-child(1):focus ~ .slider,
.menu li:nth-child(1):active ~ .slider {
  left: 0;
  background-color: #3498db;
}
.menu li:nth-child(2):hover ~ .slider,
.menu li:nth-child(2):focus ~ .slider,
.menu li:nth-child(2):active ~ .slider {
  left: 25%;
  background-color: #9b59b6;
}
.menu li:nth-child(3):hover ~ .slider,
.menu li:nth-child(3):focus ~ .slider,
.menu li:nth-child(3):active ~ .slider {
  left: 50%;
  background-color: #e67e22;
}
.menu li:nth-child(4):hover ~ .slider,
.menu li:nth-child(4):focus ~ .slider,
.menu li:nth-child(4):active ~ .slider {
  left: 75%;
  background-color: #16a085;
}

That’s all! hopefully, you have successfully created Html Css Navigation Bar With Mouse Hover Effect. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply