Transitions need a change in value to produce any effect. This is usually achieved, as you said, by switching the class or using a pseudo selector.
If you want your "transition" to occur without any changes, you need to use the animation:
#target{
width: 100px;
height:100px;
background-color:red;
}
@keyframes fadeMe {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
<div id="target" style="animation: fadeMe 2s;"></div>
Run codeHide resultI'm not sure why you will need to do this inline.
source
share