【问题标题】:Angular generated css breaks child combinatorAngular 生成的 css 破坏了子组合器
【发布时间】:2018-08-10 14:02:11
【问题描述】:

场景:


相关 CSS :

.wrapper > * {
  padding: 10px;
  flex: 1 100%;
}

这就是我得到的

.wrapper[_ngcontent-c0]    > *[_ngcontent-c0] {
  padding: 10px;
  flex: 1 100%;
 }

工作案例:

.wrapper[_ngcontent-c0]    > * {
  padding: 10px;
  flex: 1 100%;
}

问题:

  • 有没有办法阻止 Angular 这样做?
  • 我在演示中使用的 CSS 有问题吗?

【问题讨论】:

    标签: html css angular angular6


    【解决方案1】:

    尝试使用:host,更多参考Check the component styling guide

    :host .wrapper > * {
      padding: 10px;
      flex: 1 100%;
    }
    

    您也可以尝试使用/deep/

    :host /deep/ .wrapper > * {
      padding: 10px;
      flex: 1 100%;
    }
    

    嘿,我发现第二种样式有效,Checkout the stackblitz demo

    【讨论】:

    • 太棒了,成功了 :) 有一点需要注意,这必须在 app.component.css 中,styles.css 没有给出预期的结果。但这很好:)
    • @BasHamer,在他们自己的组件中使用组件样式可以让你的应用加载速度更快,重量更轻。可以分析gtmatrix或者chrome lighthouse audit的变化差异
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    相关资源
    最近更新 更多