【问题标题】:BootStrap 5.0 Styles Not Rendered in AngularBootStrap 5.0 样式未在 Angular 中呈现
【发布时间】:2021-12-04 16:27:13
【问题描述】:

我正在尝试在Angular 项目中使用BootStrap,并且能够使用项目索引文件中的以下内容在前端呈现样式:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

到目前为止还不错,但试图在不引用索引文件 BootStrap with Angular 的情况下按照此链接呈现样式。所以在 angular.json 文件中添加了以下行:

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

我相信,这就是以前的链接所做的。我不确定我是否在这里错过了什么?我所做的是以下并且不呈现按钮样式:

<button type="button" class="btn btn-primary">Add</button> //Though the class name doesn't show while writing 

【问题讨论】:

    标签: angular twitter-bootstrap angular-cli bootstrap-5


    【解决方案1】:

    您必须禁用encapsulation

    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.scss'],
      changeDetection: ChangeDetectionStrategy.OnPush,
      encapsulation: ViewEncapsulation.None,
    })
    export class AppComponent {}
    

    【讨论】:

    • 哇!非常感谢@Chris。
    猜你喜欢
    • 1970-01-01
    • 2018-02-05
    • 2019-03-20
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 2012-01-04
    • 1970-01-01
    相关资源
    最近更新 更多