Transition background-color via slide up animation

后端 未结 2 817
忘了有多久
忘了有多久 2020-11-28 11:54

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 backgrou

2条回答
  •  甜味超标
    2020-11-28 12:45

    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%);
        transition: background-position 1s;
    }
    
    .box:hover {
        background-position: 0 -100%;
    }
    

    You can see this demo here: http://jsfiddle.net/as5ZU/

提交回复
热议问题