javascript 如何更改角材料按钮的宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53334081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:10:11  来源:igfitidea点击:

How can i change the width of angular material button

javascripthtmlcssangularangular-material

提问by chaucer

How can I change the width of angular material button . I am Using angular 6.

如何更改角材料按钮的宽度。我正在使用角度 6。

回答by Dince12

You could attach a class and manipulate that.

您可以附加一个类并对其进行操作。

<button mat-raised-button class="my-class">Show</button>

then in the CSS / SASS file

然后在 CSS/SASS 文件中

.my-class{
      width: 100px!important;
      min-width: unset!important;
}

This should ensure the attribute is overwritten. BR

这应该确保属性被覆盖。BR

回答by selem mn

Merely add a style attribute (a way of diverses to do it) :

只需添加一个样式属性(一种多样化的方法):

  <button mat-raised-button color="primary" style="width : 10em;">Primary</button>

Stackblitz.

闪电战

回答by Liviu Nita

You can write it like this:

你可以这样写:

<button mat-raised-button>BUTTON</button>

Or in CSS, without !importantproperty:

或者在 CSS 中,没有!important属性:

mat-raised-button {
 width: 50px;
}

回答by Nitesh Rana

Supposing this is your button:

假设这是您的按钮:

<button id="myButton" mat-button color="primary">Primary</button>

You can go ahead an add id to button:

您可以继续向按钮添加 id:

#myButton {
width: 150px;
}