Home > Enterprise >  how to run color from right to left in button when use background-image: liner-gradient
how to run color from right to left in button when use background-image: liner-gradient

Time:12-17

I want to animate gradient buttons on hover Using HTML & CSS. but nothing is happening. Please. anyone help this situation

.btn {
  padding: 20px 40px;
  background-image: var(--gradient-button);
  color: var(--secondary-color);
  border: none;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  transition: 0.6s;
  cursor: pointer;
}
.btn:hover {
  background-position: right;
}

CodePudding user response:

You can try this :

More buttons : https://codepen.io/JavaScriptJunkie/pen/pPRooV

.buttons {
    margin: 10%;
    text-align: center;
}

.btn-hover {  
    width: 200px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    margin: 20px;
    height: 55px;
    text-align:center;
    border: none;
    background-size: 300% 100%;

    border-radius: 50px;
    moz-transition: all .4s ease-in-out;
    -o-transition: all .4s ease-in-out;
    -webkit-transition: all .4s ease-in-out;
    transition: all .4s ease-in-out;
}

.btn-hover:hover {
    background-position: 100% 0;
    moz-transition: all .4s ease-in-out;
    -o-transition: all .4s ease-in-out;
    -webkit-transition: all .4s ease-in-out;
    transition: all .4s ease-in-out;
}

.btn-hover.color {
    background-image: linear-gradient(to right, #25aae1, #40e495, #30dd8a, #2bb673);
    box-shadow: 0 4px 15px 0 rgba(49, 180, 180, 0.75);
}
<button >BUTTON</button>

CodePudding user response:

Maybe with some changes you can have it. This is just an example.

For right to left use to left in "background-image: linear-gradient(" and assign colors in it.

And maybe a white text color fit on this well.

.btn{
  border: none;
  margin: 20px;
  padding: 24px;
  width: 220px;
  font-family: "montserrat",sans-serif;
  text-transform: uppercase;
  border-radius: 6px;
  cursor: pointer;
  color: #fff;
  background-size: 200%;
  transition: 0.6s;
}

.btn1{
  background-image: linear-gradient(to left,#FFC312,#EE5A24,#FFC312);
}

.btn:hover{
  background-position: right;
}
<button >BUTTON</button>

CodePudding user response:

you were already on the right track. I have made some small modifications in a few places.

:root {
  --gradient-button: red;  
  --text-color: white;
}

.btn {
  padding: 20px 40px;
  background: var(--gradient-button);
  color: var(--text-color);
  border: none;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  background-size: 300% 100%;  
  cursor: pointer;
  moz-transition: all .4s ease-in-out;
  -o-transition: all .4s ease-in-out;
  -webkit-transition: all .4s ease-in-out;
  transition: all .4s ease-in-out;
  background-image: linear-gradient(to right, red, orange, yellow, green);
  box-shadow: 0 4px 15px 0 rgba(49, 196, 190, 0.75);
}

.btn:hover {
background-position: 100% 0;
moz-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
<button >btn</button>

  • Related