Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transition background-color via slide animation

I am trying to change the background-color of an element on hover by using CSS transitions. I want to do this by having it scroll up from the bottom. I can fade the background in using this, but I would like it to slide up:

-webkit-transition: background-color 0.5s linear; -moz-transition: background-color 0.5s linear; -o-transition: background-color 0.5s linear;   transition: background-color 0.5s linear; 

One other thought, would it be better to scroll up a separate element with the background applied to it?

like image 292
David Jones Avatar asked Dec 23 '13 22:12

David Jones


1 Answers

In order to slide the background color up you would need to use a background image, or a gradient of some sort, while gradually adjusting the background-position:

.box {     width: 200px; height: 100px;     background-size: 100% 200%;     background-image: linear-gradient(to bottom, red 50%, black 50%);     -webkit-transition: background-position 1s;     -moz-transition: background-position 1s;     transition: background-position 1s; }  .box:hover {     background-position: 0 -100%; }
<div class="box"></div>
like image 76
Sampson Avatar answered Oct 05 '22 11:10

Sampson