简体   繁体   English

如果 div 中有多个按钮,如何更改垫子凸起按钮的颜色?

[英]How to change mat-raised-button color if there are multiple buttons in a div?

[EDIT] The solution is in the comment section. [编辑] 解决方案在评论部分。

I want to change a color of a mat-raised-button, but to have a different color for every single button.我想改变垫子凸起按钮的颜色,但每个按钮都有不同的颜色。 I have the following situation:我有以下情况:

<div *ngIf="visible" class="dialog">
  <button (click)="openEditDialog()" color="accent" mat-raised-button>Edit fields</button>
  <button (click)="update()" *ngIf="showSaveCancel" color="primary" mat-raised-button>Update</button>
  <button (click)="cancel()" *ngIf="showSaveCancel" color="warn" mat-raised-button>Cancel</button>
</div>

The 'primary' and 'warn' options suit my needs for the 'Update' and 'Cancel' buttons, but I need to make the 'Edit fields' button green. “主要”和“警告”选项适合我对“更新”和“取消”按钮的需求,但我需要将“编辑字段”按钮设为绿色。 Is there a way to make that button green, with the buttons to stay in the same div?有没有办法让那个按钮变成绿色,按钮保持在同一个 div 中?

<style>
.greenButton {
  background-color: green;
}
.greenButton:hover {
  background-color: lightgreen;
}
...
</style>

<button class="greenButton" ...>

Here's a solution I've found, so if any of you guys have a similar issue, read further, the explanation is at the end:这是我找到的一个解决方案,所以如果你们中的任何人有类似的问题,请进一步阅读,解释在最后:

Original code:原始代码:

<div *ngIf="visible" class="dialog">
  <button (click)="openEditDialog()" color="accent" mat-raised-button>Edit fields</button>
  <button (click)="update()" *ngIf="showSaveCancel" color="primary" mat-raised-button>Update</button>
  <button (click)="cancel()" *ngIf="showSaveCancel" color="warn" mat-raised-button>Cancel</button>
</div>

New code:新代码:

<div *ngIf="visible" class="dialog">
  <button (click)="openEditDialog()" color="green" mat-raised-button>Edit fields</button>
  <button (click)="update()" *ngIf="showSaveCancel" color="primary" mat-raised-button>Update</button>
  <button (click)="cancel()" *ngIf="showSaveCancel" color="warn" mat-raised-button>Cancel</button>
</div>

As you can see, all I've done is to add a custom name to color value to the 'Edit fields' button, from "accent" to "green".如您所见,我所做的只是将自定义名称添加到“编辑字段”按钮的颜色值,从“重音”到“绿色”。 And then in CSS, I added然后在 CSS 中,我添加了

.mat-green {
  color: white;
  background-color: forestgreen;
}

And that's it, I hope it helped someone.就是这样,我希望它对某人有所帮助。 Cheers!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM