在 Angular2 專案中,我需要對按鈕應用一些 CSS。我想在 .html 中添加一個類并在 .scss 檔案中描述所有樣式屬性,但不幸的是,這個元素“沒有”看到該類。但是,只要我在 .html 檔案中添加與行內樣式相同的樣式 - 一切正常。
我想替換這段代碼(來自下面的代碼片段,第 5 行)
[ngStyle]="{ position: 'absolute', 'z-index': '10', right: '0' }"
通過這個
并使用test-class來自 .scss 檔案的資料。
stackblitz 的鏈接 https://stackblitz.com/edit/angular-ivy-avvwha?file=src/app/app.component.html
.html
<div>
<gridster [options]="options">
<gridster-item [item]="item" *ngFor="let item of dashboard">
<div
[ngStyle]="{ position: 'absolute', 'z-index': '10', right: '0' }"
>
<button mat-mini-fab>
<mat-icon>delete</mat-icon>
</button>
</div>
<ng-container>
<div class="outline">
<div class="header">
<div class="header-text">Text</div>
</div>
</div>
</ng-container>
</gridster-item>
</gridster>
</div>
.scss
.test-class {
position: 'absolute';
z-index: 10;
right: 0;
}
另外,也許還有其他選項可以從 .html 檔案中洗掉樣式,但我忽略了它。
先感謝您!
uj5u.com熱心網友回復:
將測驗類添加到您的元素:
<div class="test-class">
<button mat-mini-fab>
<mat-icon>delete</mat-icon>
</button>
</div>
其次是你的風格應該是absolute,而不是'absolute':
.test-class {
position: absolute;
z-index: 10;
right: 0;
}
見這里:https : //stackblitz.com/edit/angular-ivy-z8wfaj?file=src/app/app.component.scss
uj5u.com熱心網友回復:
在 Scss 檔案中 .. 你把位置:'絕對'。abosulte 不應該是一個字串。
位置:絕對;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/408381.html
標籤:
