Skip to content

Instantly share code, notes, and snippets.

@davidtranjs
Created April 27, 2023 07:18
Show Gist options
  • Save davidtranjs/0f325ecef83212d1526d4b1ebb1bac97 to your computer and use it in GitHub Desktop.
Save davidtranjs/0f325ecef83212d1526d4b1ebb1bac97 to your computer and use it in GitHub Desktop.
Scss mixins for stroke and shadow text effect
@function text-stroke(
$size: 2,
$color: #fff,
$size2: 10,
$color2: red,
$correction: 0
) {
$radius: $size - $correction;
$stroke: ();
@for $i from -$size through $size {
@for $k from -$size through $size {
$x: $k;
$y: $i;
@if $k > 0 {
$x: $k - 0.5;
}
@elseif $k < 0 {
$x: $k + 0.5;
}
@if $i > 0 {
$y: $i - 0.5;
}
@elseif $i < 0 {
$y: $i + 0.5;
}
@if ($x * $x + $y * $y <= $radius * $radius) {
$stroke: append($stroke, $i * 1px $k * 1px 0 $color, comma);
}
}
}
@if $size2 > 0 {
@for $i from $size2 through ($size2 - 4) {
$stroke: append($stroke, $i * 1px ($i - 1) * 1px 0 $color2, comma);
}
@for $i from $size2 through 0 {
$stroke: append($stroke, $i * 1px ($i - 2) * 1px 0 $color2, comma);
}
}
@return $stroke;
}
@mixin text-stroke(
$size: 2,
$color: #fff,
$size2: 10,
$color2: red,
$correction: 0
) {
text-shadow: text-stroke($size, $color, $size2, $color2, $correction);
}
// Usage
@include text-stroke(5, #ffd3e0, 5, #e10051);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment