簡體   English   中英

無法覆蓋 Angular 7 應用程序中的 Bootstrap

[英]Not able to override Bootstrap in Angular 7 app

在 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;

有人幫我嗎? 提前致謝。

使用 angular.json 加載 bootstrap.css,而不是為引導樣式導入或使用 CDN,如下所示。 順序應該是首先 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: ""; 
}

要覆蓋引導程序變量 put "$breadcrumb-divider: none;" 在 style.scss 的頂部。

  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"; ...

最新 Angular 版本的兩個簡單步驟

1)。 在 angular.json 文件中,在引導程序相關的樣式表之后添加您的自定義樣式表,就像我在代碼片段中添加的那樣

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

2)。 最后,使用ng serve命令再次手動運行您的應用程序

  1. 打開angular.json
  2. "extractCss": true更改為"extractCss": false應該可以解決問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM