Skip to content

Instantly share code, notes, and snippets.

@vldvel
Created March 15, 2018 15:24
Show Gist options
  • Save vldvel/b6d938479624358f9e565f131b8c3c48 to your computer and use it in GitHub Desktop.
Save vldvel/b6d938479624358f9e565f131b8c3c48 to your computer and use it in GitHub Desktop.
Box shadows in JavaScript
const offsetX = 10; // horizontal distance - any number
const offsetY = 10; // vertical distance - any number
const blurRadius = 20; // shadow blur - positive number - default = 0
const spreadRadius = 40; // shadow size - any number - deafult = 0
const color = 'rgba(255, 255, 199, 0.7)'; // color - rgb/rgba/hsl/hsla
// basic options
element0.style.boxShadow = `${offsetX}px ${offsetY}px ${color}`;
// full options
element1.style.boxShadow = `${offsetX}px ${offsetY}px ${blurRadius}px ${spreadRadius}px ${color}`;
// multiple shadows
element2.style.boxShadow = `${offsetX}px ${offsetY}px ${color}, -${offsetX}px -${offsetY}px ${blurRadius}px ${spreadRadius}px ${color}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment