SASS mixin for a font-awesome before/after usage











up vote
2
down vote

favorite












In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage:



I started with the following:



@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
@if $type == 'after'{
&:after {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
@if $type == 'before' {
&:before {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}
}


I then scaled it down further to the following:



@mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
$beforeOrAfter:'';

@if $type == 'after' {
$beforeOrAfter:'after';
}
@else if $type == 'before' {
$beforeOrAfter:'before';
}

&:#{$beforeOrAfter} {
content:$unicode;
font-family:"FontAwesome";
font-size:$size;
color:$color;
font-weight:$weight;
margin:$margin;
@content;
}
}


The usage would something like:



.tater {
@include font-awesome-icon(before,'f0de',2.1em,0 0 0 3em,orange,300);
}


But I feel I could make the before/after part cleaner. I basically need to determine if it is a 'before' or 'after'.










share|improve this question




























    up vote
    2
    down vote

    favorite












    In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage:



    I started with the following:



    @mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
    @if $type == 'after'{
    &:after {
    content:$unicode;
    font-family:"FontAwesome";
    font-size:$size;
    color:$color;
    font-weight:$weight;
    margin:$margin;
    @content;
    }
    }
    @if $type == 'before' {
    &:before {
    content:$unicode;
    font-family:"FontAwesome";
    font-size:$size;
    color:$color;
    font-weight:$weight;
    margin:$margin;
    @content;
    }
    }
    }


    I then scaled it down further to the following:



    @mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
    $beforeOrAfter:'';

    @if $type == 'after' {
    $beforeOrAfter:'after';
    }
    @else if $type == 'before' {
    $beforeOrAfter:'before';
    }

    &:#{$beforeOrAfter} {
    content:$unicode;
    font-family:"FontAwesome";
    font-size:$size;
    color:$color;
    font-weight:$weight;
    margin:$margin;
    @content;
    }
    }


    The usage would something like:



    .tater {
    @include font-awesome-icon(before,'f0de',2.1em,0 0 0 3em,orange,300);
    }


    But I feel I could make the before/after part cleaner. I basically need to determine if it is a 'before' or 'after'.










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage:



      I started with the following:



      @mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
      @if $type == 'after'{
      &:after {
      content:$unicode;
      font-family:"FontAwesome";
      font-size:$size;
      color:$color;
      font-weight:$weight;
      margin:$margin;
      @content;
      }
      }
      @if $type == 'before' {
      &:before {
      content:$unicode;
      font-family:"FontAwesome";
      font-size:$size;
      color:$color;
      font-weight:$weight;
      margin:$margin;
      @content;
      }
      }
      }


      I then scaled it down further to the following:



      @mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
      $beforeOrAfter:'';

      @if $type == 'after' {
      $beforeOrAfter:'after';
      }
      @else if $type == 'before' {
      $beforeOrAfter:'before';
      }

      &:#{$beforeOrAfter} {
      content:$unicode;
      font-family:"FontAwesome";
      font-size:$size;
      color:$color;
      font-weight:$weight;
      margin:$margin;
      @content;
      }
      }


      The usage would something like:



      .tater {
      @include font-awesome-icon(before,'f0de',2.1em,0 0 0 3em,orange,300);
      }


      But I feel I could make the before/after part cleaner. I basically need to determine if it is a 'before' or 'after'.










      share|improve this question















      In my SASS I use font-awesome declarations all over the place. I'm in love with it. I've created a SASS mixin for the usage:



      I started with the following:



      @mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
      @if $type == 'after'{
      &:after {
      content:$unicode;
      font-family:"FontAwesome";
      font-size:$size;
      color:$color;
      font-weight:$weight;
      margin:$margin;
      @content;
      }
      }
      @if $type == 'before' {
      &:before {
      content:$unicode;
      font-family:"FontAwesome";
      font-size:$size;
      color:$color;
      font-weight:$weight;
      margin:$margin;
      @content;
      }
      }
      }


      I then scaled it down further to the following:



      @mixin font-awesome-icon($type, $unicode, $size, $margin, $color, $weight) {
      $beforeOrAfter:'';

      @if $type == 'after' {
      $beforeOrAfter:'after';
      }
      @else if $type == 'before' {
      $beforeOrAfter:'before';
      }

      &:#{$beforeOrAfter} {
      content:$unicode;
      font-family:"FontAwesome";
      font-size:$size;
      color:$color;
      font-weight:$weight;
      margin:$margin;
      @content;
      }
      }


      The usage would something like:



      .tater {
      @include font-awesome-icon(before,'f0de',2.1em,0 0 0 3em,orange,300);
      }


      But I feel I could make the before/after part cleaner. I basically need to determine if it is a 'before' or 'after'.







      css sass mixins






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 24 at 4:44









      200_success

      127k15148411




      127k15148411










      asked Feb 23 at 16:07









      HollerTrain

      1163




      1163






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          The $type can be passed in directly to the pseudo-class selector after you check its validity.



          @if $type == 'after' or $type == 'before' {
          &:#{$type} {
          content:$unicode;
          font-family:"FontAwesome";
          font-size:$size;
          color:$color;
          font-weight:$weight;
          margin:$margin;
          @content;
          }
          }





          share|improve this answer




























            up vote
            0
            down vote













            I'm not as familiar with SASS, but why not pass $type directly:



            &:#{$type} {
            content:$unicode;
            font-family:"FontAwesome";
            font-size:$size;
            color:$color;
            font-weight:$weight;
            margin:$margin;
            @content;
            }





            share|improve this answer





















              Your Answer





              StackExchange.ifUsing("editor", function () {
              return StackExchange.using("mathjaxEditing", function () {
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
              });
              });
              }, "mathjax-editing");

              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "196"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188203%2fsass-mixin-for-a-font-awesome-before-after-usage%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote













              The $type can be passed in directly to the pseudo-class selector after you check its validity.



              @if $type == 'after' or $type == 'before' {
              &:#{$type} {
              content:$unicode;
              font-family:"FontAwesome";
              font-size:$size;
              color:$color;
              font-weight:$weight;
              margin:$margin;
              @content;
              }
              }





              share|improve this answer

























                up vote
                1
                down vote













                The $type can be passed in directly to the pseudo-class selector after you check its validity.



                @if $type == 'after' or $type == 'before' {
                &:#{$type} {
                content:$unicode;
                font-family:"FontAwesome";
                font-size:$size;
                color:$color;
                font-weight:$weight;
                margin:$margin;
                @content;
                }
                }





                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  The $type can be passed in directly to the pseudo-class selector after you check its validity.



                  @if $type == 'after' or $type == 'before' {
                  &:#{$type} {
                  content:$unicode;
                  font-family:"FontAwesome";
                  font-size:$size;
                  color:$color;
                  font-weight:$weight;
                  margin:$margin;
                  @content;
                  }
                  }





                  share|improve this answer












                  The $type can be passed in directly to the pseudo-class selector after you check its validity.



                  @if $type == 'after' or $type == 'before' {
                  &:#{$type} {
                  content:$unicode;
                  font-family:"FontAwesome";
                  font-size:$size;
                  color:$color;
                  font-weight:$weight;
                  margin:$margin;
                  @content;
                  }
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 23 at 14:13









                  Adam

                  2416




                  2416
























                      up vote
                      0
                      down vote













                      I'm not as familiar with SASS, but why not pass $type directly:



                      &:#{$type} {
                      content:$unicode;
                      font-family:"FontAwesome";
                      font-size:$size;
                      color:$color;
                      font-weight:$weight;
                      margin:$margin;
                      @content;
                      }





                      share|improve this answer

























                        up vote
                        0
                        down vote













                        I'm not as familiar with SASS, but why not pass $type directly:



                        &:#{$type} {
                        content:$unicode;
                        font-family:"FontAwesome";
                        font-size:$size;
                        color:$color;
                        font-weight:$weight;
                        margin:$margin;
                        @content;
                        }





                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          I'm not as familiar with SASS, but why not pass $type directly:



                          &:#{$type} {
                          content:$unicode;
                          font-family:"FontAwesome";
                          font-size:$size;
                          color:$color;
                          font-weight:$weight;
                          margin:$margin;
                          @content;
                          }





                          share|improve this answer












                          I'm not as familiar with SASS, but why not pass $type directly:



                          &:#{$type} {
                          content:$unicode;
                          font-family:"FontAwesome";
                          font-size:$size;
                          color:$color;
                          font-weight:$weight;
                          margin:$margin;
                          @content;
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 23 at 17:31









                          Pslice

                          586




                          586






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188203%2fsass-mixin-for-a-font-awesome-before-after-usage%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Morgemoulin

                              Scott Moir

                              Souastre