2

I have a button that needs to transition its color both when it's hovered and clicked. When clicked, I add it a class name called .selected.

Setting transition property to the button makes every style transition which is unintentional.

.score-button {
  width: 35px;
  height: 35px;
  border: 1px solid var(--fill-button-text8);
  background-color: transparent;
  border-radius: 23px;
  color: var(--fill-button-text8);
  cursor: pointer;
  font-size: 18px;
  font-weight: 600;
  transition: linear 0.5s;

  &:hover {
    background-color: var(--fill-button-bg-hover);
  }

  &.selected {
    border: none;
    background-color: var(--primary-color);
    color: var(--fill-button-text);
  }
}
0

1 Answer 1

1

You can specify a property to transition:

transition: background-color linear 0.5s;

.score-button {
    width: 35px;
    height: 35px;
    border: none;
    border: 1px solid var(--fill-button-text8);
    background-color: transparent;
    border-radius: 23px;
    color: var(--fill-button-text8);
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    transition: background-color linear 0.5s;

    &:hover {
      background-color: var(--fill-button-bg-hover);
    }

    &.selected {
      border: none;
      background-color: var(--primary-color);
      color: var(--fill-button-text);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

learned something new! thanks a lot.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.