[英]Center the content of a mat-expansion-panel in Angular material
[英]Angular Material - Set border color on a specific mat-expansion-panel
我想更改具有特定 class 的垫子扩展面板的边框颜色和宽度。
html
<div>
<mat-accordion>
<mat-expansion-panel *ngFor="let item of itemList; let i=index"
[hideToggle]="true"
[class.selected]="item.selected">
<mat-expansion-panel-header>
<mat-panel-title>{{item.header}}</mat-panel-title>
</mat-expansion-panel-header>
{{item.content}}
</mat-expansion-panel>
</mat-accordion>
</div>
ts
import { Component } from '@angular/core';
interface Item {
header: string;
content: string;
selected: boolean;
}
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
public itemList: Item[] = [
{
header: 'Item1',
content: 'This is item1.',
selected: false,
},
{
header: 'Item2',
content: 'This is item2.',
selected: true,
}
];
}
css
.selected {
border-width: 2px;
border-color: red;
}
我想为Item2
设置边框颜色红色和宽度 2px 。 但是上面的例子不起作用。
我该如何解决?
您还需要设置边框的border-style
。
.selected {
border-style: solid;
border-width: 2px;
border-color: red;
}
甚至更好:
.selected {
border: solid 2px red;
}
这是StackBlitz的变化。
如果您实际上只想设置底部边框的样式,请使用:
.selected {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: red;
}
或者:
.selected {
border-bottom: solid 2px red;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.