gpt4 book ai didi

css - Angular Material 表 - 表内边框

转载 作者:技术小花猫 更新时间:2023-10-29 11:29:17 30 4
gpt4 key购买 nike

我正在使用 Angular Material 表,我想在表内设置边框,使用 CSS 我能够设置边框:正常情况[ enter image description here
但是,当特定单元格的内容增加时,相邻单元格的边框不会增长,表格看起来很糟糕,单元格有额外内容 enter image description here
这是 CSS:

`.example-container {
display: flex;
flex-direction: column;
max-height: 500px;
min-width: 300px;
}

.mat-table {
overflow: auto;
max-height: 500px;
}
.mat-column-name{
border-left: 1px solid grey;
min-height: 48px;

}
.mat-column-weight{
border-left: 1px solid grey;

min-height: 48px;

.mat-column-symbol{
border-left: 1px solid grey;
min-height: 48px;
}`

HTML`

<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->

<!-- Position Column -->
<ng-container matColumnDef="position">
<mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.position}} </mat-cell>
</ng-container>

<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.name}} </mat-cell>
</ng-container>

<!-- Weight Column -->
<ng-container matColumnDef="weight">
<mat-header-cell *matHeaderCellDef> Weight </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.weight}} </mat-cell>
</ng-container>

<!-- Symbol Column -->
<ng-container matColumnDef="symbol">
<mat-header-cell *matHeaderCellDef> Symbol </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.symbol}} </mat-cell>
</ng-container>

<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>

`

最佳答案

方法 2:最终,我找到了解决方案,因为 Material 使用 flex-layout 我们可以使用CSS对齐 self :拉伸(stretch);/* 拉伸(stretch)“自动”大小的元素以适合容器 */ Result with align-self: stretch

这是更新后的 CSS

    `.example-container {
display: flex;
flex-direction: column;

flex-basis: 300px;
}

.mat-table {
overflow: auto;
max-height: 500px;
}

.mat-column-name{
border-right: 1px solid grey;
align-self: stretch;
text-align: center


}
.mat-column-position{
border-right: 1px solid grey;
align-self: stretch;
text-align: center;

}
.mat-column-weight{
border-right: 1px solid grey;
align-self: stretch;
text-align: center;

}
.mat-column-symbol{

text-align: center;
align-self: stretch;
}
.mat-column-weight{
align-self: stretch;
} `

关于css - Angular Material 表 - 表内边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48237779/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com