[英]How to apply css global class different only in one component ? Angular
I need to select all.modal-content class ( that is modal ) on my application except some component.除了某些组件外,我需要在我的应用程序上使用 select all.modal-content class (即 modal )。 Example I need to target all component where is exist.modal-content except component Users.示例我需要定位除组件用户之外的所有exist.modal-content 组件。 And what I try:我尝试的是:
.modal-content:not(app-users) {
background: red;
}
This is apply and on app-users component.这适用于应用程序用户组件。 Selector for app-users应用程序用户的选择器
@Component({
selector: 'app-users',
templateUrl: './app-users.component.html',
styleUrls: ['./app-users.component.scss']
})
I am try everythink... I am also try with inside component Users:我想尽一切办法......我也尝试使用内部组件用户:
.modal-content {
background:red;
}
@Component({
selector: 'app-users',
templateUrl: './app-users.component.html',
styleUrls: ['./app-users.component.scss'],
encapsulation: ViewEncapsulation.None
})
This is work, but when come to Users component this css background: red is affected on all others components....这是可行的,但是当谈到用户组件时,这个 css 背景:红色会影响所有其他组件......
I am also try with:我也在尝试:
::ng-deep .modal-content {
background:red;
}
Same situation.同样的情况。 WHen come to Users component affected after on all component.当在所有组件上受到影响的用户组件时。 I need我需要
.modal-content {
background:red;
}
Only for USERS component for others 30 component I need different color.仅适用于其他 30 个组件的用户组件,我需要不同的颜色。 How to fix it?如何解决?
You can add a custom class to all modals under your users
component.您可以将自定义 class 添加到users
组件下的所有模式。 Then you can write a simple style to add different colours for modals under users
component.然后你可以编写一个简单的样式来为users
组件下的模式添加不同的颜色。
For example, add a class called 'user-modal' to your modal under user component like below.例如,在用户组件下的模态中添加一个名为“user-modal”的 class,如下所示。
<div class="modal-dialog">
<div class="modal-content user-modal">
...
</div>
</div>
Then you can style it differently on your css file like below然后您可以在 css 文件上设置不同的样式,如下所示
.modal-content:not(.user-modal){
background:red;
}
.modal-content.user-modal{
background:blue;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.