【发布时间】:2021-05-06 22:03:25
【问题描述】:
我有这个带有<ng-content> 的文件上传组件。当用户将文件从操作系统悬停到文件上传区域时,组件内的所有标签都从 .fileover 类继承 background-color: rgba(121, 211, 255, 0.15);。但是我无法更改<ng-content> 内部的.ag-center-cols-viewport 的背景颜色。我尝试使用::slotted 和::ng-deep。最后的图片显示,如果我更改 chrome devtols 内部的颜色,background-color: red; 可以工作。
任何建议为什么这不起作用?
HTML:
<div>
<div class="containerDragDrop" appDnd (fileDropped)="onFileDropped($event)">
<input class="inputDragDrop file-input" type="file" #fileupload accept="{{accept}}"
[disabled]="disabled" multiple
(change)="addFiles($event)"/>
<ng-content class="fileDropRef"></ng-content>
<div class="middleFileText">
</div>
<label *ngIf="choseFileToggle" class="labelDragDrop" (click)="fileupload.click()">Välj Filer</label>
</div>
</div>
带有 ::slotted 的 CSS:
.fileover {
.middleFileText{
opacity: 0.8;
}
background-color: rgba(121, 211, 255, 0.15);
:host ::slotted(.ag-center-cols-viewport) {
background-color: rgba(121, 211, 255, 0.15) !important;
}
}
带有 ::ng-deep 的 CSS:
.fileover {
.middleFileText{
opacity: 0.8;
}
background-color: rgba(121, 211, 255, 0.15);
:host ::ng-deep .ag-center-cols-viewport {
background-color: rgba(121, 211, 255, 0.15) !important;
}
}
【问题讨论】: