How can I change the width of angular material button? I am using angular 6.
Asked
Active
Viewed 7.1k times
7
-
1show us what you already tried? – devedv Nov 16 '18 at 08:34
-
There is a simple button .I want to reduce its width – chaucer Nov 16 '18 at 08:39
-
Got the answer.Must use min-width Duplicate of [https://stackoverflow.com/questions/33148095/is-it-possible-to-make-an-md-button-smaller](https://stackoverflow.com/questions/33148095/is-it-possible-to-make-an-md-button-smaller) – chaucer Nov 16 '18 at 09:14
-
min-width is not working with version 8.1.1 – Newbie Sep 09 '19 at 08:37
4 Answers
31
You could attach a class and manipulate that.
<button mat-raised-button class="my-class">Show</button>
then in the CSS / SASS file
.my-class{
width: 100px!important;
min-width: unset!important;
}
This should ensure the attribute is overwritten. BR

devDan
- 5,969
- 3
- 21
- 40
-
But the width is not decreasing beyond a certain limit .It is only increasing but the issue is with decreasing. – chaucer Nov 16 '18 at 08:49
-
Regarding [this suggested edit of yours](https://stackoverflow.com/review/suggested-edits/21430659): please do not try to edit posts which are clearly off-topic. All you added was more reason to close it as being a tool-recommendation, or even Primarily Opinion Based. Another problem is that the first edit on a question after it has been put on hold puts a question into the reopen queue, whereas subsequent edits won't. You therefor take the OP's chance for improving the question. Do keep editing, just make sure they're worth it! – Adriaan Nov 16 '18 at 09:04
-
2
-
-
1
1
You can write it like this:
<button mat-raised-button>BUTTON</button>
Or in CSS, without !important
property:
mat-raised-button {
width: 50px;
}

Adriaan
- 17,741
- 7
- 42
- 75

Liviu Nita
- 11
- 4
0
Merely add a style attribute (a way of diverses to do it) :
<button mat-raised-button color="primary" style="width : 10em;">Primary</button>

SeleM
- 9,310
- 5
- 32
- 51
-4
Supposing this is your button:
<button id="myButton" mat-button color="primary">Primary</button>
You can go ahead an add id to button:
#myButton {
width: 150px;
}

Nitesh Rana
- 512
- 1
- 7
- 20