【发布时间】:2015-03-01 13:41:34
【问题描述】:
是否有推荐的方法让图标字体(例如 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。)
【问题讨论】:
-
shadow dom 不加载带有@font-face 的字体。至少在 Chrome 中。您还必须在 shadow dom 之外包含 CSS 声明。见:robdodson.me/at-font-face-doesnt-work-in-shadow-dom
标签: font-face web-component shadow-dom icon-fonts octicons