【发布时间】:2019-06-07 17:27:04
【问题描述】:
我有一个“Sidenav”组件,我在其中使用 svg 作为菜单图标,但我无法从组件 scss 文件中将样式应用于这些图标,它只能在全局 scss 文件中使用。
由于我处理“svg”、“polygon”、“path”....标签,它在组件 scss 文件中不起作用。
有没有办法让它工作,因为我只在我的组件中使用那些 svg?
代码示例:
<div id="sidenav-icon-section">
<li class="bleu-icon">
<a href="/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve" data-inject-url="http://localhost:4200/assets/images/menu_items/accueil.svg" _ngcontent-c1="">
<polygon fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="32,3 2,33 11,33 11,63 23,63 23,47 39,47 39,63 51,63 51,33 62,33 "></polygon>
</svg>
</a>
</li>
</div>
这个 css 代码可以在我的全局 scss 文件中工作,但不能在我的组件 css 文件中工作:
#sidenav-icon-section {
.bleu-icon polygon {
transition: .2s !important;
}
&:hover .bleu-icon polygon {
stroke: #009999 !important;
}
}
甚至任何像这样的css属性:
svg {
dislay: none;
}
【问题讨论】:
-
请提供相关代码,最好是minimal reproducible example。
-
@ccprog 现在完成了。