英文:
Angular 15 Material Design table styling not working anymore
问题
我想要样式化Angular中的Angular Material表格中的表行和单元格。
但是在Angular 15中,以简单的CSS样式为例的“旧”示例不再起作用:
table {
width: 100%;
border-spacing: 0 8px !important;
}
td.mat-cell {
padding: 16px 0 16px 0;
border-bottom: 2px solid #ffa600;
border-top: 2px solid #ffa600;
}
tr.mat-row {
background: #79a1d8;
}
无论我在组件的CSS文件中使用什么样式,表格设计都保持不变。
这是Angular Material Design的基本表格示例,通过一些样式进行扩展,但没有效果。
Angular Material Design的基本表格示例
从旧版本(如版本8)到当前版本15,Angular进行了哪些更改,导致表格样式失效?
英文:
I want to style the table rows and cells in an Angular Material Table in Angular.
But the "old" examples with simple css styles don't work anymore in Angular 15:
table {
width: 100%;
border-spacing: 0 8px !important;
}
td.mat-cell {
padding: 16px 0 16px 0;
border-bottom: 2px solid #ffa600;
border-top: 2px solid #ffa600;
}
tr.mat-row {
background: #79a1d8;
}
No matter what styles in the component's css file I use, the table design stays the same.
Here is the basic Table-Example of the Angular Material Design - extended by some styles - with no effects.
https://stackblitz.com/edit/angular-kwfygf?file=src/app/table-basic-example.css
What does Angular changed from older versions like version 8 to the current version 15, that let the table styles fail?
答案1
得分: 3
以下是翻译好的部分:
"你尝试定位的元素没有类,而是似乎具有使用不同样式语法的属性。"
table {
width: 100%;
border-spacing: 0 8px !important;
}
td[mat-cell] {
padding: 16px 0 16px 0;
border-bottom: 2px solid #ffa600;
border-top: 2px solid #ffa600;
}
tr[mat-row] {
background: #79a1d8;
}
"这段CSS似乎有效。"
希望这对你有所帮助。如果还有其他需要翻译的部分,请告诉我。
英文:
The elements you try to target don't have classes, instead they seem to be having attributes which use different styling syntaxes.
table {
width: 100%;
border-spacing: 0 8px !important;
}
td[mat-cell] {
padding: 16px 0 16px 0;
border-bottom: 2px solid #ffa600;
border-top: 2px solid #ffa600;
}
tr[mat-row] {
background: #79a1d8;
}
This CSS seems to work.
https://stackblitz.com/edit/angular-kwfygf-kdthdr?file=src%2Fapp%2Ftable-basic-example.css
Here is a very small example of the difference in case the link stops working:
<!-- begin snippet: js hide: true console: true babel: false -->
<!-- language: lang-css -->
table {
width: 100%;
border-spacing: 0 8px !important;
}
/** Styling for attributes **/
td[mat-cell] {
padding: 16px 0 16px 0;
border-bottom: 2px solid orange;
border-top: 2px solid orange;
}
tr[mat-row] {
background: skyblue;
}
/** For classes **/
td.mat-cell {
padding: 16px 0 16px 0;
border-bottom: 2px solid green;
border-top: 2px solid green;
}
tr.mat-row {
background: pink;
}
<!-- language: lang-html -->
<!-- table with attributes -->
<table mat-table>
<tr mat-row>
<td mat-cell> Table with attributes </th>
</tr>
<tr mat-row>
<td mat-cell> Name </th>
</tr>
</table>
<!-- table with classes -->
<table class=mat-table>
<tr class=mat-row>
<td class=mat-cell> Table with classes </th>
</tr>
<tr class=mat-row>
<td class=mat-cell> Name </th>
</tr>
</table>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论