/ Text

Text css 3d shadow mixin

Text css 3d shadow mixin

Text css 3d shadow mixin

An experiment with more or less realistic shadows. The next step would be a direction parameter for the light source and more color and contrast automation...

Made with

Html
Css/SCSS

html

<div class="font">Codetea<span>.</span>com</div>

Css/SCSS

$background: #E0E0E0;
$secondary: salmon;

body { margin-top:255px;background: $background; font-size:60px; text-align:center; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; font-family: "Avenir Next", "Helvetica Neue", sans-serif}


@mixin shadow($color, $steps, $glow) {
  $all: ();
  $all: append($all, -1px 1px 0 rgba($color,.1), comma);
  $all: append($all, 1px -1px 0 rgba($glow,.1), comma);
  $all: append($all, 1px -1px 25px $glow, comma);
  @for $i from 1 through $steps {
    $all: append($all, append($i*-1px $i*1.9px $i*1px, rgba($color,2/$i)));
  }
  text-shadow: $all;
}

// Second mixin as I still have to figure out the direction parameters...
@mixin shadow-alternate($color, $steps, $glow) {
  $all: ();
  $all: append($all, -1px -1px 0 rgba($color,.1), comma);
  $all: append($all, 1px 1px 0 rgba($glow,.1), comma);
  $all: append($all, 1px -1px 25px $glow, comma);
  @for $i from 1 through $steps {
    $all: append($all, append($i*-1px $i*-1.9px $i*1px, rgba($color,2/$i)));
  }
  text-shadow: $all;
}

.font, .font span {transition: 2s;}

.font {
  cursor: pointer;
  -webkit-transform:translate3d(0,50%,0) rotate(0deg);
  color: $background;
  @include shadow( darken($background,25%), 25, white );
  span {
    color: $secondary;
    @include shadow( darken(desaturate($secondary, 80%),20%), 25, lighten($secondary,10%) )
      }
  &:hover {
    -webkit-transform:translate3d(0,100%,0) rotate(-90deg);
    @include shadow-alternate( darken($background,20%), 25, white );
    span {
    color: $secondary;
    @include shadow-alternate( darken(desaturate($secondary, 80%),20%), 25, lighten($secondary,10%) )
      }
  }
}

Author

Gerhard Bliedung

Demo

See the Pen css 3d shadow mixin by Gerhard Bliedung (@bldng) on CodePen.

CodeTea

A Nice collection of often useful examples done in HTML JavaScript CSS.

Read More