CSS3 to achieve menu hover effect

CSS3 to achieve menu hover effect

Result:

html

<nav id="nav-1">
  <a class="link-1" href="#">Home</a>
  <a class="link-1" href="#">About</a>
  <a class="link-1" href="#">Contact</a>
  <a class="link-1" href="#">Shop</a>
</nav>

<nav id="nav-2">
  <a class="link-2" href="#">Home</a>
  <a class="link-2" href="#">About</a>
  <a class="link-2" href="#">Contact</a>
  <a class="link-2" href="#">Shop</a>
</nav>

<nav id="nav-3">
  <a class="link-3" href="#">Home</a>
  <a class="link-3" href="#">About</a>
  <a class="link-3" href="#">Contact</a>
  <a class="link-3" href="#">Shop</a>
</nav>

CSS

@import url(https://fonts.googleapis.com/css?family=Raleway);
body {
  margin: 0px;
}
nav {
  margin-top: 40px;
  padding: 24px;
  text-align: center;
  font-family: Raleway;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
}
#nav-1 {
  background: #3fa46a;
}
#nav-2 {
  background: #5175C0;
}
#nav-3 {
  background: #EEA200;
}

.link-1 {
  transition: 0.3s ease;
  background: #3fa46a;
  color: #ffffff;
  font-size: 20px;
  text-decoration: none;
  border-top: 4px solid #3fa46a;
  border-bottom: 4px solid #3fa46a;
  padding: 20px 0;
  margin: 0 20px;
}
.link-1:hover {
  border-top: 4px solid #ffffff;
  border-bottom: 4px solid #ffffff;
  padding: 6px 0; 
}

.link-2 {
  transition: 0.6s;
  color: #ffffff;
  font-size: 20px;
  text-decoration: none;
  border-right: 2px dotted transparent;
  padding: 30px 8px 0 10px;
  margin: 0 10px;
}
.link-2:hover {
  border-right: 2px dotted #ffffff;
  padding-bottom: 24px;
}
.link-3 {
  transition: 0.4s;
  color: #ffffff;
  font-size: 20px;
  text-decoration: none;
  padding: 0 10px;
  margin: 0 10px;
}
.link-3:hover {
  background-color: #ffffff;
  color: #EEA200;
  padding: 24px 10px;
}

The above is the details of how to achieve menu hover effect with CSS3. For more information about CSS3 menu hover, please pay attention to other related articles on 123WORDPRESS.COM!

<<:  Analysis and solution of the reasons why HTML external reference CSS files are not effective

>>:  Implementation example of Docker deployment of front-end and back-end separation projects

Recommend

A brief discussion on VUE uni-app custom components

1. Parent components can pass data to child compo...

Use docker to deploy tomcat and connect to skywalking

Table of contents 1. Overview 2. Use docker to de...

Detailed steps to install docker in 5 minutes

Installing Docker on CentOS requires the operatin...

Vue global filter concepts, precautions and basic usage methods

Table of contents 1. The concept of filter 1. Cus...

Solutions to Files/Folders That Cannot Be Deleted in Linux

Preface Recently our server was attacked by hacke...

Summary of considerations for writing web front-end code

1. It is best to add a sentence like this before t...

jQuery implements a simple carousel effect

Hello everyone, today I will share with you the i...

Example of deploying Laravel application with Docker

The PHP base image used in this article is: php:7...

CSS stacking and z-index example code

Cascading and Cascading Levels HTML elements are ...

jQuery implements form validation function

jQuery form validation example / including userna...

How to block IP and IP range in Nginx

Written in front Nginx is not just a reverse prox...

Analysis of the principles and usage of Linux hard links and soft links

In the Linux system, there is a kind of file call...

htm beginner notes (must read for beginners)

1. What is HTML HTML (HyperText Markup Language):...