Bootstrap 4 Glyphicons未显示在Angular 4项目中 [英] Bootstrap 4 Glyphicons not showing on Angular 4 project

查看:63
本文介绍了Bootstrap 4 Glyphicons未显示在Angular 4项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Sass的Bootstrap 4进行​​Angular 4项目,我想使用字形图标,但是当我使用以下代码时:

I'm working on an Angular 4 Project using Bootstrap 4 with Sass, and I want to use the glyphicons but when I use the following code:

<button class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-thumbs-up"></span>Like</button>

例如,当创建一个赞"按钮时,该图标不会显示.

For example, when making a "like" button, the icon doesn't show.

我将项目配置为使用ng-serve命令编译SCSS样式表,我的angular-cli.json看起来像这样:

I configured the project to compile the SCSS stylesheets with the ng-serve command, my angular-cli.json looks like this:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "front-end-informatorio"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "../node_modules/bootstrap/scss/bootstrap.scss",
        "../node_modules/bootstrap/scss/main.scss"

      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
}

我尝试在我的index.html中将其链接:

I tried linking this in my index.html:

<link data-require="bootstrap-css@3.3.6" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css"/>

它使图标起作用,但也改变了我项目的整个样式.

It made the icons work, but also also changed the whole style of my project.

如何在不重叠样式的情况下实现它?

How do I achieve it without overlapping the styles?

推荐答案

Bootstrap 4删除了Glyphicons支持. (请参阅: https://getbootstrap.com/docs/4.0/migration/#components)

Bootstrap 4 dropped Glyphicons support. (see: https://getbootstrap.com/docs/4.0/migration/#components)

这意味着您需要使用其他一些图标字体,例如字体很棒.

This means that you'll need to use some other icon font, like Font Awesome.

  1. 入门页面
  2. 中获取脚本
  3. 将其粘贴到您的<head>
  4. 开始使用!!在 FontAwesome.com
  5. 上搜索图标
  6. 浏览文档,释放Font Awesome的全部潜能!
  1. Grab the script from the get started page
  2. Paste it in your <head>
  3. Start using! Search for the icons on FontAwesome.com
  4. Explore the docs to unleash the full potential of Font Awesome!

示例:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Bootstrap + Font Awesome</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css">
    <script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
  </head>
  <body>
    <div class="container">
      <!-- display 4 class makes the font size increase -->
      <h1 class="display-4"><i class="fab fa-stack-overflow"></i></h1>
      <p>That was easy! <i class="far fa-thumbs-up"></i></p>
      <button type="button" class="btn btn-primary">Works also with buttons! <i class="fas fa-link"></i></button>
    </div>
  </body>
</html>

Font Awesome团队正在研究Angular Font Awesome组件.现在已经发布了,但是您可以在此处找到它.

The Font Awesome team is working on an Angular Font Awesome component. It is right now in pre-release, but you can find it here.

这篇关于Bootstrap 4 Glyphicons未显示在Angular 4项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆