css - 导入的样式不适用于组件
问题描述
我想创建单独的文件来存储 IE 9-11 的样式。为此,我创建了文件并将其导入InternetExplorer.scss
到主文件中styles.scss
:
@import "scss/InternetExplorer.scss";
有InternetExplorer.scss
一种风格:
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
.nav-tabs .nav-item {
margin-bottom: -1px;
z-index: 0;
}
}
但是,声明的样式不会应用于页面。
但是,如果我在组件的样式属性中声明此样式,则可以完美应用 IE 样式:
@Component({
selector: 'tabComponent',
templateUrl: 'tabComponent.module.html',
styles:
`@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
.nav-tabs .nav-item {
margin-bottom: -1px;
z-index: 0;
}
}`,
encapsulation: ViewEncapsulation.None
样式的位置是:
app/styles.scss
app/scss/InternetExplorer.scss
的位置tabComponent
是:
app/coreComponents/tabComponent
如果我用两个点写@import "../scss/InternetExplorer.scss";
,那么File to import not found or unreadable: ../scss/InternetExplorer.scss.
如果我用一个点写@import "./scss/InternetExplorer.scss";
,则不应用样式。
Angular 版本是 6。
如何应用样式InternetExplorer.scss
?
解决方案
来自 Angular 文档:
/* AOT 编译器需要
./
显示这是本地的 */
由于您的 scss 文件夹不在本地,请尝试添加./
到路径:
@import "./scss/InternetExplorer.scss";
推荐阅读
- http - 修复 HttpHeader 中的 CRLF 序列时遇到 NoClassDefFoundError
- javascript - angular 2 - ngFor 动态函数
- php - 正则表达式函数将模式的第二次出现添加到第一次出现
- angular - Angular:将对象传递给指令
- php - 从 CSV 文件计算价格 - PHP/JS
- keras - Keras 中的按列操作
- python - 两种方法可以指向相同的代码吗?
- javascript - 从父状态重新排序子组件的问题
- php - 在购物车和结帐时显示篮子中的物品总数,以及电子邮件订单收据
- php - 使用php将特殊字符传递给mysql数据库