admin管理员组文章数量:1410724
Consider, I have few elements which use Shadow DOM to hide their internal div-soup and layout.
Even tough they are different, they share the same CSS style sheet, as they are using the same set of elements that are supposed to be styled in consistent manner. This could be, for example, a CSS framework (bootstrap).
The problem is that this style sheet is pretty big.
What is the most efficient way to share such big style sheet between many Shadow Roots (in SD V1)?
Consider, I have few elements which use Shadow DOM to hide their internal div-soup and layout.
Even tough they are different, they share the same CSS style sheet, as they are using the same set of elements that are supposed to be styled in consistent manner. This could be, for example, a CSS framework (bootstrap).
The problem is that this style sheet is pretty big.
What is the most efficient way to share such big style sheet between many Shadow Roots (in SD V1)?
Share Improve this question asked Dec 5, 2016 at 11:41 tomalectomalec 90011 silver badges27 bronze badges1 Answer
Reset to default 8UPDATE: 2019 - Use Constructable stylesheets
As of 2019, Constructable stylesheets is the approach to apply stylesheets to shadow DOM and web ponents in general. Read more about it here.
Previous answer:
You can use an import
CSS rule at the first line of a <style>
element defined in the Shadow DOM:
<div id=D1></div>
<template id=T1>
<style>
@import url( '/css/stylesheet.css' )
</style>
...
</template>
Then import the <template>
content
in the Shadow DOM root:
var root = D1.attachShadow( {mode: open } )
root.appendChild( T1.content.cloneNode( true ) )
本文标签: javascriptHow to apply common CSS styles to many Shadow Roots at onceStack Overflow
版权声明:本文标题:javascript - How to apply common CSS styles to many Shadow Roots at once? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744830334a2627309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论