Transition "Fill from left" into background

Asked

Viewed 221 times

1

I need to make a transition Fill from left in the background of a button. Something much like what you’re in http://h5bp.github.io/Effeckt.css/dist/#0 (search for the button "Fill from left").

I want that when I hover the mouse over it, it fills the background from left to right. My syntax is like this:

  .BT{
    font-size: 12px;
    height: 30px;
    left: 330px;
    line-height: 30px;
    top: 350px;
    width: 110px;
}

And the hover of that button, which is wrong, is like this:

.BT:hover{background-color:red;
transform:translate(-10%, 0px); 
transition:transform 500ms ease 0s;
}

What happens is he’s moving the button, wanted to do a test to move internally.

1 answer

1


The code you placed is to move the button. If you want to move the background you can animate the position of it: (jsfiddle)

.btn {
  background: #fff linear-gradient(90deg, #8f2 50%, #59f 50%);
  background-position: 0% center;
  background-size: 200%;
}

.btn:hover {
  background-position: 100% center;
}

If you want to animate an element inside the button look at this example: jsfiddle.

  • Your tip worked 100%. I have just one question, I saw you used CSS3, does it roll in IE8? D

  • 1

    He just won’t have the smooth transition.

  • And I had already forgotten: you have to change the background for a static image.

  • Dude, okay 10, now I’m going to ask you a really stupid question, how do you make him transition from left to right? the opposite of what he is now?

  • Change the background-position.

  • I made changes to "background-position" and was unsuccessful. =/

  • 1

    Change the value background-position between the rules with and without :hover.

  • Got it, thank you again! : D . btn { background: #fff linear-gradient(90deg, #8f2 50%, #59f 50%); background-position: 100% center; background-size: 200%; Transition: background-position 1s; text-align: center; padding: 1em; } . btn:Hover { background-position: 0% center; }

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.