【问题标题】:Not able to override Bootstrap in Angular 7 app无法在 Angular 7 应用程序中覆盖 Bootstrap
【发布时间】:2019-06-25 16:12:15
【问题描述】:

在 Angular 应用程序中,我试图通过删除分隔线来覆盖我的 breadcrumb。我用https://getbootstrap.com/docs/4.2/components/breadcrumb/#example

但不起作用。这是我的 angular.json

    {
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ibo": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "styleext": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/ibo",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "stylePreprocessorOptions": {
                "includePaths": [
                  "node_modules/bootstrap",
                  "src/styles"
                ]
             },
            "scripts": [
              "node_modules/popper.js/dist/umd/popper.min.js",
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ],
            "styles": [
               "node_modules/font-awesome/css/font-awesome.min.css",
               "node_modules/bootstrap/dist/css/bootstrap.min.css",
               "src/styles/styles.scss",
            ],
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ibo:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "ibo:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ibo:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.scss"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "ibo-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "ibo:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "ibo:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "ibo"
}

我的 style.scss:

    @import '~bootstrap/scss/_functions.scss';
    @import '~bootstrap/scss/_variables.scss';
    @import '~bootstrap/scss/mixins/_breakpoints.scss';
    @import 'global.scss';

    $grid-breakpoints: (
        sm: 768px,
        md: 768px,
        lg: 1024px
    );

    $container-min-widths: (
      sm: 768px,
      md: 768px,
      lg: 1024px
    );

    //resets;-



    html,body{
        padding: 0;
        margin: 0;
        height: 100%;
    }
    .wrapper.container-fluid{
        min-height: 100%;
        padding:0;
        margin: 0;
    }

    $breadcrumb-divider: none !important;

有人帮帮我吗?提前致谢。

【问题讨论】:

  • 尝试添加!important 可能有帮助
  • @JohnVelasquez - 但医生没有这么说。还是试过了,不行
  • 你把这个导入到你的styles.scss了吗?
  • 尝试将您的 $breadcrumb-divider 变量移动到第一行
  • @JohnVelasquez - 你想让我从哪里删除?

标签: angular twitter-bootstrap sass angular7


【解决方案1】:

不用导入或使用 CDN 作为引导样式,而是使用 angular.json 加载 bootstrap.css,如下所示。顺序应该是先 bootstrap.css 然后 style.css

"styles": [
             "../node_modules/bootstrap/dist/css/bootstrap.min.css",
             "src/styles/styles.scss",
          ],

您可以使用下面的 css 来覆盖分隔符。这不会覆盖引导变量。

.breadcrumb>li+li:before { 
    padding: 0 5px; 
    color: #ccc; 
    content: ""; 
}

要覆盖引导变量放入“$breadcrumb-divider: none;”在 style.scss 的顶部。

【讨论】:

  • 这个 @import "~bootstrap/scss/bootstrap"; 我已经在应用程序中导入了 style.scss 对吗?
  • 你可以删除它
  • 删除并添加喜欢你的建议,没有运气!!
  • 能否请您更新您尝试过的问题.... 更新 angular.json 文件后也重新运行 ng serve 命令
  • .breadcrumb>li+li:before { padding: 0 5px;颜色:#ccc;内容: ””; }
【解决方案2】:
  1. 从 angular.json 中删除 bootstrap.min.css

    ....
    "styles": [
       "node_modules/font-awesome/css/font-awesome.min.css",
       "src/styles/styles.scss",
    ],
    ....
    
  2. 导入bootstrap.scss 文件。

    @import "~bootstrap/scss/bootstrap";
    
  3. @import 语句之前设置$breadcrumb-divider

    $breadcrumb-divider: none;
    
    @import "~bootstrap/scss/bootstrap";
    ...
    

【讨论】:

    【解决方案3】:

    最新 Angular 版本的两个简单步骤

    1)。在 angular.json 文件中,在引导相关样式表之后添加您的自定义样式表,就像我在代码 sn-p 中添加的那样

    "styles": [
        "./node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
     ],
    

    2)。最后使用ng serve 命令再次手动运行您的应用程序

    【讨论】:

      【解决方案4】:
      1. 打开angular.json
      2. "extractCss": true 更改为"extractCss": false 应该可以解决问题

      【讨论】:

        猜你喜欢
        • 2020-11-21
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 2021-01-22
        • 2020-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多