S
S
sorry_i_noob2019-08-31 23:16:37
Sass
sorry_i_noob, 2019-08-31 23:16:37

How to write such a mixin in SASS?

The text-shadow property in CSS can have a lot of values. They are listed separated by commas. Here is an example:

text-shadow: -0.5px -0.5px 0 #fff,
        0.5px -0.5px 0 #fff,
        -0.5px 0.5px 0 #fff,
        0.5px 0.5px 0 #fff,
        0 0 17.9px rgba(255, 255, 255, 0.16);

The first 4 values ​​make the text stroke. The fifth value makes the text glow.
I want to write a mixin that allows strokes. And at the same time add more values. I wrote like this:
@mixin text-stroke($weight, $color) {
    text-shadow: $weight -$weight 0 $color,
    $weight -$weight 0 $color,
    -$weight $weight 0 $color,
    $weight $weight 0 $color,
    @content;
}

But SASS throws an error:
Invalid CSS after "...eight 0 $color,": expected ";", was "@content;"

How can I write such a mixin? Is this even possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2019-08-31
@sorry_i_noob

expected ";"

Expected ;
It was@content
@mixin text-stroke($weight, $color) {
    text-shadow: $weight -$weight 0 $color,
    $weight -$weight 0 $color,
    -$weight $weight 0 $color,
    $weight $weight 0 $color;
    @content;
}

UPD : solution
@mixin text-stroke($weight, $color, $rest...) {
    text-shadow: $weight -$weight 0 $color,
      $weight -$weight 0 $color,
      -$weight $weight 0 $color,
      $weight $weight 0 $color,
      $rest;
}

body {
  @include text-stroke(10, #fff, ffffffffffff 1 1 1,  ffffffffff 2 2 2);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question