Home > Web Front-end > CSS Tutorial > Why Isn't My Hover Menu Background Transitioning Smoothly?

Why Isn't My Hover Menu Background Transitioning Smoothly?

DDD
Release: 2024-12-05 09:33:09
Original
882 people have browsed it

Why Isn't My Hover Menu Background Transitioning Smoothly?

Transition Effect for Hovering Menu Background

Question:

Despite using CSS transitions, the background color of menu items does not change smoothly on hover. Here's the relevant CSS:

#content #nav a:hover {
    color: black;
    background-color: #AD310B;
    -moz-transition: all 1s ease-in;
    -webkit-transition: all 1s ease-in;
    -o-transition: all 1s ease-in;
    transition: all 1s ease-in;
}
Copy after login

Answer:

Browser support is essential for transitions to function correctly. As of the time of writing, transitions are supported in:

  • Safari
  • Chrome
  • Firefox
  • Opera
  • Internet Explorer 10

To achieve the desired fade effect, consider the following CSS:

a {
    background-color: #FF0;
}

a:hover {
    background-color: #AD310B;
    -webkit-transition: background-color 1000ms linear;
    -ms-transition: background-color 1000ms linear;
    transition: background-color 1000ms linear;
}
Copy after login

This ensures that background color transitions work in supported browsers, creating a smooth fading effect when hovering over menu links:

<a>Navigation Link</a>
Copy after login

The above is the detailed content of Why Isn't My Hover Menu Background Transitioning Smoothly?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template