element-font-awesome icon indicating copy to clipboard operation
element-font-awesome copied to clipboard

how to use sass

Open kobezone opened this issue 6 years ago • 5 comments

can you offered demo how to use sass? when i use sass element-ui & font-awesome it can't work

kobezone avatar Sep 04 '17 06:09 kobezone

Here is my sample code:

  1. defined prefix and path variables
  2. import entry scss file
[class^="el-icon-fa"], [class*=" el-icon-fa"] {
  display: inline-block;
  font: normal normal normal 14px/1 FontAwesome!important;
  font-size: inherit;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
};

$fa-css-prefix: el-icon-fa;
$fa-font-path: "~@/../node_modules/font-awesome/fonts";

@import '~@/../node_modules/font-awesome/scss/font-awesome.scss';

kaiye avatar Sep 12 '17 08:09 kaiye

Try the following:

// font-awesome: Concatenates with '/' between path and font name.
$fa-font-path: '~font-awesome/fonts';
$fa-css-prefix: el-icon-fa;

@import '~font-awesome/scss/font-awesome';

[class^='#{$fa-css-prefix}-'], [class*=' #{$fa-css-prefix}-'] {
  display: inline-block;
  font: normal normal normal #{$fa-font-size-base}/#{$fa-line-height-base} FontAwesome !important;
  font-size: inherit;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

My project is using Webpack. Can't remember if the ~ prefix is Webpack or Sass specific.

jpickwell avatar Oct 20 '17 18:10 jpickwell

I actually found a simpler option that allows FontAwesome's size classes to work.

// font-awesome: Concatenates with '/' between path and font name.
$fa-font-path: '~font-awesome/fonts';
$fa-css-prefix: el-icon-fa;

@import '~font-awesome/scss/font-awesome';

[class^='#{$fa-css-prefix}-'], [class*=' #{$fa-css-prefix}-'] {
  font-family: FontAwesome !important; // override ElementUI's icon font
}

jpickwell avatar Oct 24 '17 21:10 jpickwell

There are 3 types of icon font in fontawesome-free: "^5.8.1": solid, regular, light. All I got is the solid. How could I use the regular or light one? @jpickwell

Even-Lau avatar Mar 26 '19 01:03 Even-Lau

@Even-Lau,

FA 5 has 4 sets: solid, regular, light, and brands. Light is not free. Only a sub-set of solid and regular are free. Brands is completely free, all icons included.

When I made those comments, I was using FA 4. Now I'm using FA 5, and I use the SVG+JS version instead of web fonts (IE may not allow web fonts to load). I also no longer use ElementUI. However, FA has a Vue component, and all the icons can be used directly through JS without using SCSS. To use with ElementUI, you might have to dig through their code looking for icon slots that you can override.

jpickwell avatar Mar 26 '19 17:03 jpickwell