1

is it possible in CSS3 to let a class just add new transition properties to an existing transition instead of replacing the old transition definition?

For example:

.transition-a {
transition: opacity 0.3s ease-in;
}

.transition-b {
transition: color 0.3s ease-in !important;
}
<div class="transition-a transition-b">
</div>

would overwrite transition-a instead of adding an additional property to the exisitng transition definition.

It would be nice if it would be possible to compose different classes like mixins resulting in a property like

transition: color 0.3s ease-in, opacity 0.3 ease-in`

without the need to explicitly specify a rule for the combination of both classes that would force you to repeat yourself.

EDIT: More Details

I currently use the SASS source of Bootstrap and want to apply an additional transition on Bootstraps .badge class. I have an additional class .fade containing the following:

.custom-badge.fade {
transition: opacity 0.3s ease-in !important;

It would work fine if it wouldn't overwrite the definitions of Bootstraps .badge class transition property. I simply want to add an additional transition property to the exiting color transitions.

Sebi2020
  • 1,966
  • 1
  • 23
  • 40

2 Answers2

0

It's not possible.

But, my workaround in these situation is to break up the short syntax and rewrite just the property that needs to change, so you can preserve the rest.

In this case:

.transition-a {
  transition-property: opacity;
  transition-duration: .3s;
  transition-timing-function: ease-in;
}

.transition-b {
  transition-property: opacity, color;
}
  

NB: you can omit !important if .transition-b is declared after .transition-a NB2: this works great with background images.

alula
  • 101
  • 4
0

If the transitions have the same duration, delay, and easing, you can always fall back on using transition-property: all:

.transition-a {
  transition: opacity 0.3s ease-in;
}

.transition-b {
  transition-property: all;
}

Ostensibly there's a performance hit for using all (see this answer, for instance), but it's not something I've ever noticed.

spacejake
  • 21
  • 1
  • 4