How to use global css styles in shadow dom

前端 未结 4 757
孤城傲影
孤城傲影 2021-01-07 22:58

Shadow dom encapsulate css styles, selectors don\'t cross the shadow boundary.

Question: How to use global common css styles in shadow

4条回答
  •  半阙折子戏
    2021-01-07 23:41

    Non of the provided links work for me in Chrome 66 (as of 2018) so I ended up with this to customize custom element from outside:

    
      
    
    
    class Element extends HTMLElement {
        constructor() {
            super();
            var shadow = this.attachShadow({mode: 'open'});
    
            var user_style = shadow.host.innerHTML.match(/