:host getting oveerirden by universal selector css

后端 未结 1 484
名媛妹妹
名媛妹妹 2021-01-21 22:29

We have CSS resets (margin:0px;padding:0px;) in a common style file which we have authored as one component and have included as a part of other components which we

1条回答
  •  失恋的感觉
    2021-01-21 22:48

    As we expect :host to have more specificity over universal selector strangely this is not the case. universal selector styles are overriding our :hoststyles

    It's a wrong asumption. Actually, any CSS selector defined in the containing document will override the :host CSS rules.

    According to Google's Shadow DOM presentation:

    Outside styles always win over styles defined in shadow DOM. For example, if the user writes the selector fancy-tabs { width: 500px; }, it will trump the component's rule: :host { width: 650px;}

    As a workaround, use !important combined with :host if you need.

    0 讨论(0)
提交回复
热议问题