Font-awesome: Extending multiple FA* styles within a custom Sass = Bug

Created on 18 May 2018  路  6Comments  路  Source: FortAwesome/Font-Awesome

Extending multiple FA* styles within a custom Sass file renders only one style in the compiled CSS

I have a rating stars component to design with our CMS solution. So I want to avoid depending on HTML markup that can get corrupted by site editors when posting new content. For that reason I integrated FontAwesome 5 PRO using 芦 _Web fonts with CSS_ 禄, over the 芦 _SVG with Javascript_ 禄 option, and everything seemed to work fine... Until I had needed both font styles Solid and Regular to render side by side.

So far I've been able to render FAR icons within my localhosted (for now) solution by extending FontAwesome's Sass library. My problem is that I'm unable to render any other styles then that REGULAR via including+extending FA class names.

Requirements

Environment

My Bugged Result

Maybe I'm not coding it the proper way!?

My custom HTML source

<div class="score-value" title="50%">
    <strong itemprop="ratingValue">2.5</strong>
</div>
<div class="score-icons five-icons" data-rounded-icons="2 half">
    <i class="icon ico-star first-icon"></i>
    <i class="icon ico-star second-icon"></i>
    <i class="icon ico-star third-icon"></i>
    <i class="icon ico-star fourth-icon"></i>
    <i class="icon ico-star fifth-icon"></i>
</div>

My custom SCSS code

.icon {

    @include fa-icon;
    @extend .far;     // regular 馃憤
    &.fill {
        @extend .fas; // solid 馃憥 
    }
    &.light {
        @extend .fal; // light
    }
    &.logo {
        @extend .fab; // brands (note: this term conflicts with Bootstrap's library)
    }

    &.ico-star {
        // whole + outlined (default)
        &:before {
            content: fa-content($fa-var-star); //馃憤
        }
        // half + outlined
        &.half:before {
            content: fa-content($fa-var-star-half); //馃憤
        }
        // whole + filled
        &.fill:before {
            content: fa-content($fa-var-star);
        }
        // half + filled
        &.fill.half:before {
            content: fa-content($fa-var-star-half);
        }
    }
}
bug css

Most helpful comment

SCSS extend creates these these bugs, by messing up the order of things.
If there are provided these kinds of "helpers", why shouldn't we be able to use them? Why would we have to know, that that specific font-weight switches things, if there are these helpers, that abstract these things.

Given this scss

    &>.NavLink:after {
        @include fa-icon;
        @extend .fas;
        content: fa-content($fa-var-chevron-right);
    }

Produces this output:

image

The font-weight is set by .fas class, then overridden by fa-icon mixin. In the result, icon is not rendered correctly.

Switching things on/off I noticed - @extend .fas adds all of the properties necessary for the icon. And @include fa-icon just resets them...

    &>.NavLink:after {
        //@include fa-icon;
        @extend .fas;
        content: fa-content($fa-var-chevron-right);
    }

image

So removing @include fa-icon fixes the problem, I would guess if OP would remove it, all of his cases would work correctly!

And perhaps doc's or examples should be updated by removing @include part?

All 6 comments

Hi,

just some hints, not a solution, at the moment.

I think that this is not an issue

If you wanto to switch icon style, you just need to change the font weight from 400 to 300 or 900. Ref: https://fontawesome.com/how-to-use/web-fonts-with-css#basic-use

So, something like

.icon {
  @include fa-icon;
  @extend .far;

  &.fill {
    font-weight: 900;
  }

  &.light {
    font-weight: 300;
  }
}

Also, content: fa-content($fa-var-star); is going to return the same result, so you could remove the duplicate code

&.ico-star {
  &:before {
    content: fa-content($fa-var-star); //馃憤
  }
  &.half:before {
    content: fa-content($fa-var-star-half); //馃憤
  }
}

@tagliala that is a marvelous hint! I completely missed that font-weight details from their documentation.

SCSS extend creates these these bugs, by messing up the order of things.
If there are provided these kinds of "helpers", why shouldn't we be able to use them? Why would we have to know, that that specific font-weight switches things, if there are these helpers, that abstract these things.

Given this scss

    &>.NavLink:after {
        @include fa-icon;
        @extend .fas;
        content: fa-content($fa-var-chevron-right);
    }

Produces this output:

image

The font-weight is set by .fas class, then overridden by fa-icon mixin. In the result, icon is not rendered correctly.

Switching things on/off I noticed - @extend .fas adds all of the properties necessary for the icon. And @include fa-icon just resets them...

    &>.NavLink:after {
        //@include fa-icon;
        @extend .fas;
        content: fa-content($fa-var-chevron-right);
    }

image

So removing @include fa-icon fixes the problem, I would guess if OP would remove it, all of his cases would work correctly!

And perhaps doc's or examples should be updated by removing @include part?

Thanks @leqwasd! Was confused why my Sass implementation wasn't working (following the docs). Removing @include fa-icon; solved this issue for me.

Wow this makes me so mad. Using the paid version and I spent 3 hours debugging trying to figure out why this wasn't working, turns out the documentation is just wrong.

THANK YOU @leqwasd!

@cfbauer sorry for the troubles and thanks for the heads-up

I can see that the documentation at https://fontawesome.com/how-to-use/on-the-web/using-with/sass#mixins has been partially changed to extend %fa-icon instead of @include (which is still mentioned in the section) and the example produces the correct output:

@import "./fontawesome/scss/fontawesome.scss";
@import "./fontawesome/scss/regular.scss";
@import "./fontawesome/scss/solid.scss";
@import "./fontawesome/scss/brands.scss";

.user {
  @extend %fa-icon;
  @extend .fas;

  &:before {
    content: fa-content($fa-var-user);
  }
}

.user-regular {
  @extend %fa-icon;
  @extend .far;

  &:before {
    content: fa-content($fa-var-user);
  }
}

.twitter {
  @extend %fa-icon;
  @extend .fab;

  &:before {
    content: fa-content($fa-var-twitter);
  }
}

Output:

image

How are you loading the scss files in you project?

Any chance that you are using https://github.com/FortAwesome/font-awesome-sass ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davegandy picture davegandy  路  284Comments

quxiaofeng picture quxiaofeng  路  160Comments

mitch621 picture mitch621  路  180Comments

joshuabarney picture joshuabarney  路  163Comments

bhubbard picture bhubbard  路  169Comments