有没有推荐的方法让图标字体(例如 FontAwesome/Octicons)渗入 Shadow DOM?
目前,当我想在自定义元素的 Shadow DOM 中使用图标时,我必须在 Shadow DOM 中包含部分ociticons.css
文件内联:
#shadowroot
<style>
.octicon, .mega-octicon {
font: normal normal normal 16px/1 octicons;
display: inline-block;
text-decoration: none;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.mega-octicon { font-size: 32px; }
.octicon-search:before { content: '\f02e'} /* */
</style>
<button>
<span class="mega-octicon octicon-search"></span>
</button>
(显然,@font-face
确实会渗入 Shadow DOM。)