2

I'm trying to set a transition for this button I have on this mockup navbar I'm making and when I hover over, I want a 0.5s transition for a background change, but it isn't working I haven't really used transitions much in css, but this is what the great google has told me :

.btn-primary {
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    padding: 6px;
    background: -webkit-linear-gradient(bottom, #0066FF 0, #0088FF 85%, #00AAFF 100% );
    font-size: 14px;
    color: white;
}

.btn-primary:hover {
    background: -webkit-linear-gradient(bottom, #0000CC 0, #0044CC 100%);
    cursor: pointer;
    -webkit-transition: background 0.3s linear;
}

Demo: http://codepen.io/anon/pen/lApnj

Any information would be great thanks! :)

Willem de Wit
  • 8,604
  • 9
  • 57
  • 90
Datsik
  • 14,453
  • 14
  • 80
  • 121

2 Answers2

1

There isn't any support for CSS3 gradient transition. YET. However, you could try something like this:

Button

<a class="btn_primary" href="#">A button</a>

CSS

.btn_primary {
    background-color : #6BFF8A;
    background-image : linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.2) 100%);
    color : #fff;
    display : block;
    font-family : arial,sans-serif;
    font-size : 12px;
    padding : 5px 10px;
    text-align : center;
    text-decoration : none;
    transition : background-color 0.5s ease 0s;
    width : 75px;
}
.btn_primary:hover {
    background-color : #900;
}

And here's a little fiddle I created for you.

0

you have to put the transition in the normal state of your class like this:

.btn-primary {
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    padding: 6px;
    background: -webkit-linear-gradient(bottom, #0066FF 0, #0088FF 85%, #00AAFF 100% );
    font-size: 14px;
    color: white;
    -webkit-transition: background 0.3s linear;
}

.btn-primary:hover {
    background: -webkit-linear-gradient(bottom, #0000CC 0, #0044CC 100%);
    cursor: pointer;

}

EDIT: this is actually wrong since, as Kacey said, there is no support for transition with gradients. Sorry for the mistake

Yenn
  • 919
  • 6
  • 20