【问题标题】:How to have a component without inherited css in Angular 6如何在Angular 6中拥有一个没有继承css的组件
【发布时间】:2021-05-20 17:39:25
【问题描述】:

我有一个使用 Angular 6 和 Bootstrap 的项目,现在,我只需要创建一个可以在移动设备中使用的响应式页面。所以,我需要在没有从项目继承的任何 css 的情况下创建这个页面/组件。我怎样才能做到这一点?一旦我创建了页面,它已经有一些标签,比如和 css 类,我只是不知道它们在哪里导入到这个组件中

【问题讨论】:

    标签: css angular frontend angular6


    【解决方案1】:

    一个选项是将 viewEncapsulation 设置为 ShadowDom

    @Component({
      selector: 'app-test-comp',
      templateUrl: './test-comp.component.html',
      styleUrls: ['./test-comp.component.css'],
      encapsulation: ViewEncapsulation.ShadowDom
    })
    export class TestCompComponent {}

    但要注意浏览器的支持。更多信息:

    【讨论】:

    • 这甚至会删除我在“./test-comp.component.css”中的 CSS。 navBar 和 sideBar 等其他组件仍在其中...
    猜你喜欢
    • 2018-06-23
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    相关资源
    最近更新 更多