Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Insert SASS Mixin variable in comment

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #42179
    uneart
    Member

    Hi, just a quick question cause I can’t find any resources online. I got the following SASS mixin to add my font-sizes in rem with fallback:

    @mixin rem-font-size ($size) {
    font-size: $size + px; font-size: ($size / 10) + rem; /* =$size + px */
    }
    and it compiles to

    font-size: 16px;
    font-size: 1.6rem;
    /* =$size + px */

    which is pretty much I wanted. Except that I want the value of $size displayed in the comment as well. Any ideas how to solve that?

    #121941
    rosspenman
    Participant

    By referencing the variable like this: #{$var}, you can force Sass to output it in places where it usually wouldn’t.

    So you should be able to use.

    @mixin rem-font-size ($size) {
    font-size: $size + px; font-size: ($size / 10) + rem; /* =#{$size + px} */
    }

    #121943
    uneart
    Member

    Awesome, works perfectly! Thanks @rosspenman. Do you know online resource where I can look something like that up myself next time? I could not find it in the official SASS reference that one is hard to read I think.

    #121946
    rosspenman
    Participant

    [It actually is in the Sass documentation](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#interpolation_), but it isn’t explained very well.

    #121947
    rosspenman
    Participant

    I just kind of guessed that it would work, and it did! :)

    #121951
    uneart
    Member

    Ah it is even in there. Someone should definitely write a nicer doc for SASS.

    #121979
    Kitty Giraudel
    Participant
    #121991
    rosspenman
    Participant

    Wow! That’s cool!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.