Skip to content

Instantly share code, notes, and snippets.

@crazyrohila
Last active December 30, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyrohila/7821242 to your computer and use it in GitHub Desktop.
Save crazyrohila/7821242 to your computer and use it in GitHub Desktop.
SCSS mixin for generating 3D button
/**
* variables:-
* @bgcolor: background color.
* @color: font color in button.
* @shdow-depth: depth for box-shadow around button.
*/
@mixin button($bgcolor, $color, $shadow-depth) {
// Box shadow array.
$shadow: ();
// Reset default things.
border: 0;
outline: 0;
appearence: none;
cursor: pointer;
// fallback background color.
background-color: $bgcolor;
background: $bgcolor;
color: $color;
// Box-shadow stuff.
@for $i from 1 through $shadow-depth {
@for $j from 0 through 1 {
$shadow: $shadow, $i+0px $i+$j+(-1px) 0 darken($bgcolor, 10%);
}
}
box-shadow: $shadow;
// position. will use for active state.
position: relative;
// Hover state.
&:hover {
background: darken($bgcolor, 5%);
}
// Active state.
&:active {
top: $shadow-depth+0px;
left: $shadow-depth+0px;
background: darken($bgcolor, 10%);
box-shadow: none;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment