Skip to content

Instantly share code, notes, and snippets.

@joeldrapper
Last active December 10, 2015 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeldrapper/4452213 to your computer and use it in GitHub Desktop.
Save joeldrapper/4452213 to your computer and use it in GitHub Desktop.
Handy little snippet for generating block shadows with SASS.
=vendor($property, $value)
-webkit-#{$property}: $value
-moz-#{$property}: $value
-o-#{$property}: $value
#{$property}: $value
=block-shadow($distance, $horizontal, $vertical, $color)
$property: null
$i: 1
@while $i <= $distance
@if $horizontal == left and $vertical == bottom
$property: $property , -#{$i}px #{$i}px $color
@else if $horizontal == left and $vertical == top
$property: $property , -#{$i}px -#{$i}px $color
@else if $horizontal == right and $vertical == bottom
$property: $property , #{$i}px #{$i}px $color
@else if $horizontal == right and $vertical == top
$property: $property , #{$i}px -#{$i}px $color
$i: $i + 1
+vendor(box-shadow, $property)
.box
+block-shadow(5px, left, bottom, #ddd)
.box {
-webkit-box-shadow: -1px 1px #dddddd, -2px 2px #dddddd, -3px 3px #dddddd, -4px 4px #dddddd, -5px 5px #dddddd;
-moz-box-shadow: -1px 1px #dddddd, -2px 2px #dddddd, -3px 3px #dddddd, -4px 4px #dddddd, -5px 5px #dddddd;
-o-box-shadow: -1px 1px #dddddd, -2px 2px #dddddd, -3px 3px #dddddd, -4px 4px #dddddd, -5px 5px #dddddd;
box-shadow: -1px 1px #dddddd, -2px 2px #dddddd, -3px 3px #dddddd, -4px 4px #dddddd, -5px 5px #dddddd;
}
@joeldrapper
Copy link
Author

Just updated this to fix a bug where the first shadow is always using the left bottom direction. The output remains unchanged as the bug didn't effect this use case.

@joeldrapper
Copy link
Author

Changed three of the if statements to else if statements for better performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment