Overgang van achtergrondkleur

Ik probeer een overgangseffect te maken met background-colorbij het zweven van menu-items, maar het werkt niet. Hier is mijn CSS-code:

#content #nav a:hover {
    color: black;
    background-color: #AD310B;
    /* Firefox */
    -moz-transition: all 1s ease-in;
    /* WebKit */
    -webkit-transition: all 1s ease-in;
    /* Opera */
    -o-transition: all 1s ease-in;
    /* Standard */
    transition: all 1s ease-in;
}

De #navdivis een menu ulLijst met items.


Antwoord 1, Autoriteit 100%

Voor zover ik weet, werken overgangen momenteel in Safari, Chrome, Firefox, Opera en Internet Explorer 10 +.

Dit zou een fade-effect voor u moeten produceren in deze browsers:

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;
}
<a>Navigation Link</a>

Antwoord 2, Autoriteit 17%

Voor mij is het beter om de overgangscodes met de originele / minimale selectors te plaatsen dan met de: Hover of andere extra selectors:

#content #nav a {
    background-color: #FF0;
    -webkit-transition: background-color 1000ms linear;
    -moz-transition: background-color 1000ms linear;
    -o-transition: background-color 1000ms linear;
    -ms-transition: background-color 1000ms linear;
    transition: background-color 1000ms linear;
}
#content #nav a:hover {
    background-color: #AD310B;
}
<div id="content">
    <div id="nav">
        <a href="#link1">Link 1</a>
    </div>
</div>

Antwoord 3

Een andere manier om dit te bereiken is het gebruik van animationdie meer controle biedt.

#content #nav a {
    background-color: #FF0;
    /* only animation-duration here is required, rest are optional (also animation-name but it will be set on hover)*/
    animation-duration: 1s; /* same as transition duration */
    animation-timing-function: linear; /* kind of same as transition timing */
    animation-delay: 0ms; /* same as transition delay */
    animation-iteration-count: 1; /* set to 2 to make it run twice, or Infinite to run forever!*/
    animation-direction: normal; /* can be set to "alternate" to run animation, then run it backwards.*/
    animation-fill-mode: none; /* can be used to retain keyframe styling after animation, with "forwards" */
    animation-play-state: running; /* can be set dynamically to pause mid animation*/
    /* declaring the states of the animation to transition through */
    /* optionally add other properties that will change here, or new states (50% etc) */
    @keyframes onHoverAnimation {
    0% {
      background-color: #FF0;  
    }
    100% {
      background-color: #AD310B;
    }
  }
}
#content #nav a:hover {
    /* animation wont run unless the element is given the name of the animation. This is set on hover */
    animation-name: onHoverAnimation;
}

Other episodes