Is it possible to @import bootstrap icons in the scss file and use it via @extend in other scss classes?
Asked Answered
O

3

8

Is it possible to import and extend the bootstrap-icons.css in the scss file like importing the bootstrap.scss?

What I've tried so far without success:

@import "../node_modules/bootstrap-icons/font/bootstrap-icons";

.right-square-icon{
  font-size: 4rem;
  @extend .bi;
  @extend .bi-caret-right-square;
  @extend .text-dark;
}

with the error:

The selector ".bi" was not found.

Onagraceous answered 9/9, 2021 at 17:51 Comment(0)
O
8

Yes it is possible to import bootstrap-icons via scss.

@import "~bootstrap-icons/font/bootstrap-icons.css";
Orozco answered 18/9, 2021 at 16:49 Comment(3)
Hi Bes, unfortunately this is the same behavior like with @import "../node_modules/bootstrap-icons/font/bootstrap-icons"; just another denotation of the pathOnagraceous
This works perfectly with sass.Teirtza
@use "bootstrap-icons/font/bootstrap-icons.css"; is better.Hushaby
N
5

You can import the "bootstrap-icons.scss" file and edit the font files' location variable like this -

$bootstrap-icons-font-src: url("../webfonts/bootstrap-icons.woff2") format("woff2"), url("../webfonts/bootstrap-icons.woff") format("woff");

@import "~bootstrap-icons/font/bootstrap-icons.scss";
Noiseless answered 29/12, 2021 at 13:32 Comment(1)
It works for me but I am wondering what is ?30a.... importance after font name ?Bradstreet
P
3

All response is incomplete or wrong.

You need 2 things :

  • override $bootstrap-icons-font-src bootstrap variable which set by wrong path compilation for webpack encore

  • import bootstrap-icons.scss with relative path in your global.scss file

Result :

$bootstrap-icons-font-src: url("../../node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff2") format("woff2"), url("../../node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff") format("woff");
@import "../../node_modules/bootstrap-icons/font/bootstrap-icons.scss";

Then, just this run like a charm :

<i class="bi bi-plus-square-fill" style="font-size: 2rem; color: cornflowerblue;"></i>

Context of response :

  • PHP 8
  • Symfony 6.2
  • Webpack encore
Pardon answered 18/2, 2023 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.