简体   繁体   中英

Output a variable with a SASS mixin

I am trying to do something along the lines of:

@mixin raleway() {
    @include font-face("ralewayregular", font-files("raleway/raleway-regular-webfont.woff", "raleway/raleway-regular-webfont.ttf", "raleway/raleway-regular-webfont.svg"), "raleway/raleway-regular-webfont.eot");
    $raleway: "ralewayregular", Arial, sans-serif;
}

Then, to use the mixin:

@include raleway();

body {
    font: 16px $raleway;
}

But, I am getting a Undefined variable: "$raleway". error when I try to compile. It looks like the mixin does not make the variable available, does anyone know if this is possible in SASS?

Nico O pretty much says it in his comment, but her's an example. Put the following code near the top of your file:

@include font-face("ralewayregular", font-files("raleway/raleway-regular-webfont.woff", "raleway/raleway-regular-webfont.ttf", "raleway/raleway-regular-webfont.svg"), "raleway/raleway-regular-webfont.eot");
$raleway: "ralewayregular", Arial, sans-serif;

Then later in the file when you want to use the font:

body { font: 16px $raleway; }

Check out this link if you want to read up on variable scope in Sass. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM