3

I am having trouble creating a @mixin for a drop shadow. The drop shadow I want in regular CSS is as follows

-webkit-box-shadow: 0px 2px 3px 2px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0px 2px 3px 2px rgba(0, 0, 0, 0.2);
box-shadow: 0px 2px 3px 2px rgba(0, 0, 0, 0.2);

The @mixin I have created is as such

@mixin box-shadow(
    $top, $left, $blur, $size, $color) {
}

Then to use this I have added the below to my scss file

@include box-shadow(0, 2px, 3px, 2px, rgba(0, 0, 0, 0.2));

However, it is broken as I do not see any drop shadow CSS being applied once the SCSS is compiled.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Al-76
  • 1,738
  • 6
  • 22
  • 40

4 Answers4

6

Try this: Fiddle

@mixin box-shadow($top, $left, $blur, $size, $color) {
   -webkit-box-shadow: $top $left $blur $size $color;
   -moz-box-shadow: $top $left $blur $size $color;
   box-shadow: $top $left $blur $size $color;
}

.box{
  width:150px;
  height:150px;
  background:blue;
  @include box-shadow(2px,2px,5px,0, rgba(0,0,0,0.6));
}
Ganesh Yadav
  • 2,607
  • 2
  • 29
  • 52
1

It looks like you've left out declaring the box-shadow rules in your mixin.

It should look like this:

@mixin box-shadow($top, $left, $blur, $size, $color) {
  box-shadow: $top $left $blur $size $color
}

Add the vendor prefixes as you need.

fiddle

sol
  • 22,311
  • 6
  • 42
  • 59
0

I use this

/* BOXSHADOW */
@mixin boxshadow(@x: 0, @y: 0, @blur: 0, @spread: 0, @rgba: rgba(0, 0, 0, 1.0)) {
  -webkit-box-shadow: @x*@rem @y*@rem @blur*@rem @spread*@rem @rgba;
  -moz-box-shadow:    @x*@rem @y*@rem @blur*@rem @spread*@rem @rgba;
  box-shadow:         @x*@rem @y*@rem @blur*@rem @spread*@rem @rgba;
}

@include boxshadow(0, 0, 10, -5, rgba(220, 220, 220, 1.0));
Al-76
  • 1,738
  • 6
  • 22
  • 40
0

You could try to use Compass. It provides a lot of mixins for the most common CSS rules, including box-shadow. It also transparently add cross-browser prefixes while using its mixins.

Davide Caruso
  • 104
  • 2
  • 5