Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Box-Shadow Transition Performance

DZone's Guide to

Box-Shadow Transition Performance

One trick you can try to improve the performance of a box-shadow transition is moving the box-shadow to a pseudo-element.

· Performance Zone ·
Free Resource

SignalFx is the only real-time cloud monitoring platform for infrastructure, microservices, and applications. The platform collects metrics and traces across every component in your cloud environment, replacing traditional point tools with a single integrated solution that works across the stack.

Adding a CSS transition to animate the box-shadow of an element is a handy trick.

It's a design technique that's often used on hover to highlight something. If you've used this effect you might have noticed that sometimes the performance can be suboptimal making the animation slow.

One trick you can try to improve the performance is moving the box-shadow to a pseudo-element.

Slower

Direct transition of the box-shadow property:

.box-shadow {  
  box-shadow: 0 3px 5px 0 rgba(0,0,0,0.08);
  transition: box-shadow 0.3s ease-in-out;
}
.box-shadow:hover {  
  box-shadow: 0 5px 15px 2px rgba(0, 0, 0, 0.1);
}

Faster

Pre-render the hover state of the box-shadow with a pseudo-element and hide it by setting the opacity:0:

.box-shadow::after {  
  box-shadow: 0 5px 15px 2px rgba(0, 0, 0, 0.1);
  opacity: 0; /* hide the hover shadow */
  transition: opacity 0.3s ease-in-out;
}

Apply the transition with the opacity property:

.box-shadow:hover::after  {  
  opacity: 1; /* show the hover shadow */
}

That's it!

SignalFx is built on a massively scalable streaming architecture that applies advanced predictive analytics for real-time problem detection. With its NoSample™ distributed tracing capabilities, SignalFx reliably monitors all transactions across microservices, accurately identifying all anomalies. And through data-science-powered directed troubleshooting SignalFx guides the operator to find the root cause of issues in seconds.

Topics:
box shadow ,performance ,tutorial ,speed

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}