css - 如何使用 ng2-bootstrap 覆盖 angular2 中的 twitter bootstrap 样式

标签 css angular ng2-bootstrap

我正在使用来自 valor-software 的 ng2-bootstrap。当我使用 ng serve 启动网站时,提供的页面在标题中有以下样式标签:

<style type="text/css">/* You can add global styles to this file, and also import other style files */
</style>

<style type="text/css">/*!
 * Bootstrap v3.3.7 (http://getbootstrap.com)
 * Copyright 2011-2016 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 *//*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}

它显然是从 node_modules/bootstrap/dist/css/bootstrap.css 文件中提取第二个内联样式。我想覆盖 body 标签上的背景颜色。我可以更改节点模块文件夹中的 bootstrap.css 文件,但感觉这不是正确的解决方案。

更改 style.css 文件不会执行任何操作。即使更改 index.html 文件似乎也无济于事。样式似乎已被覆盖。

如有任何帮助,我们将不胜感激。

谢谢

最佳答案

经过一番挖掘,我找到了解决方案。

angular-cli.json 文件中的内容如下:

"apps": [
{
  "root": "src",
  "outDir": "dist",
  "assets": [
    "assets",
    "favicon.ico"
  ],
  "index": "index.html",
  "main": "main.ts",
  "test": "test.ts",
  "tsconfig": "tsconfig.json",
  "prefix": "app",
  "mobile": false,
  "styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.min.css"
  ],
  "scripts": [],
  "environments": {
    "source": "environments/environment.ts",
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }
}

],

我只需要切换样式的顺序

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

并将任何覆盖添加到 src/styles.css 文件

关于css - 如何使用 ng2-bootstrap 覆盖 angular2 中的 twitter bootstrap 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41101685/

相关文章:

angular2-routing - Uncaught Error : Module build failed: Error: No PostCSS Config found in:\ng2-admin\node_modules\bootstrap-loader at Error (native)

java - 在单个服务器上使用 Angular 2 运行 Spring4MVC

html - 如何使html中的下拉菜单与另一个div重叠

Angular 6 - 获取 FormGroup 上所有更改的值

javascript - 遵循指南后,ngx-auth-firebaseui 无法工作,有关 StyleUtils 的错误

Angular 2 : *ngFor does not update when array is updated

html - 用文本扩展 Div

css - 是否可以阻止稍微太大的内联图像(例如笑脸)影响其所在文本 block 的行高?

html - 我如何在 CSS/HTML 中获得粘性页脚?

angular - 无法让 ng2-bootstrap 模态显示在 bs-modal-backdrop 之上