Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a CSS transition while keeping previously declared transitions

Say we got an element which has a transition. How can one add a class with a transition for another transition property without overwriting and so disabling the other transition?

Example

HTML:

<div class="foo bar">
  Lorem ipsum dolor sit amet …
</div>

CSS:

.foo {
  transition: background-color 1s ease-in-out;
}

.bar {
  transition: box-shadow 0.5s linear;
  /* This of course overwrites .foo */
}
like image 659
luke Avatar asked Dec 09 '25 14:12

luke


1 Answers

Basically, you can't. You would have to write a new selector .foo.bar with both transitions stated. –

.foo {
  transition: background-color 1s ease-in-out;
}

.bar {
  transition: box-shadow 0.5s linear;
}

.foo.bar {
  transition: background-color 1s ease-in-out, box-shadow 0.5s linear;
}
like image 185
Paulie_D Avatar answered Dec 11 '25 19:12

Paulie_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!