7

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

peterh
  • 11,875
  • 18
  • 85
  • 108
chaucer
  • 91
  • 1
  • 1
  • 4

4 Answers4

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
    `min-width` was my problem. Thanks – Gil Epshtain Dec 22 '19 at 12:23
  • Most welcome :') – devDan Dec 23 '19 at 08:34
  • 1
    min-width: unset!important; that was the key ;) – Smaillns Jun 03 '20 at 10:17
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>

Stackblitz.

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