【发布时间】:2019-09-06 05:52:12
【问题描述】:
我有一个组件,当我将 css 代码添加到该组件的 .css 文件时,它可以工作。但是如果我将代码移到 style.css 中,它就不起作用了。
我的 html
<div class="content-body mat-elevation-z8">
<mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="transKey">
<mat-header-cell *matHeaderCellDef mat-sort-header> trans no </mat-header-cell>
<mat-cell *matCellDef="let row">
<a (click)="showDetail(row.url, row.transKey)" >
{{row.transKey}}
</a>
</mat-cell>
</ng-container>
</mat-table>
</div>
我的 CSS
.content-body a {
cursor: pointer;
text-decoration: none;
color: #4c90c7
}
.content-body a:hover {
color: #346092;
}
.content-body a:visited {
text-decoration: none;
color: #4c90c7
}
但是,并非所有组件都无法正常工作,以下是我的文件结构。 Style.css 适用于 'dashboard' html,但不适用于 'trans-msg-his-dialog' html。我想知道为什么,如果它与trans-msg 的module.ts 有关。
有人可以帮忙吗?谢谢。
文件结构:
更新 根据 StepUp 的评论,我检查了 Chrome Inspector 并发现以下内容:
“仪表板”有效:
'trans-msg-his-dialog' 不起作用:
但是,我不确定第一部分是什么,我在我的 css 中找不到它们。我想知道它是否与Bootstrap有关?
a:not([href]):not([tabindex]) {
color: inherit;
text-decoration: none;
}
更新2 计算样式如下所示,但是我在任何 css 中都找不到 'rgba(0, 0, 0, 0.87)'。我还尝试将那些与 a 相关的 css 移动到 style.css 的底部,但没有运气。
【问题讨论】:
-
如果您必须覆盖一个样式,请在单个样式的末尾添加
!important。即:color: red !important; -
@JacopoSciampi 谢谢,我添加了 !important 并且它确实有效!但是我想知道为什么 style.css 确实适用于一个组件而不适用于另一个组件。
-
在这里你可以找到答案:stackoverflow.com/questions/9245353/… -> 基本上
style.css中定义的样式在trans-msg-his-dialog.css之后应用。!important!键 -says- 接受它作为值,忽略为该类或 id 定义的所有其他规则 -
@JacopoSciampi 我明白了。知道了,谢谢!