37

I want my buttons showing left- and right arrow and NOW text to be as small as possible. How do I do that?

<div ng-controller="DateCtrl" layout="row" flex>
     <md-datepicker ng-model="activeDate" md-placeholder="Enter date" ng-change="changeDate()"></md-datepicker>
     <div>
         <md-button class="md-raised" ng-click="prev()">&lt;</md-button>
         <md-button class="md-raised" ng-click="changeToday()">NOW</md-button>
         <md-button class="md-raised" ng-click="next()">&gt;</md-button>
     </div>
</div>

With the current solution the buttons will be arranged as if they were in a layout="column", that is vertically.

Before I dig into this CSS-style, I just wanted to check if there is a preferred Angular-Material way of doing this?

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
Andreas Selenwall
  • 5,705
  • 11
  • 45
  • 58
  • 1
    Do you want the text itself to be smaller or the button itself, have you considered adding a custom class to the buttons and just add your own styling and then reuse that class where ever you might feel you want to use this again? – TrojanMorse Oct 15 '15 at 12:17
  • I just want the button to be smaller, the text should be the same size. There is supposed to be an .md-mini class, but it doesn't do anything with the button size. I am looking into using md-icon-button instead, will try it out later today and see if I get smaller buttons then. – Andreas Selenwall Oct 15 '15 at 13:08

10 Answers10

41

Add the following to your styles:

.md-button {
    min-width: 1%;
}

Alternatively, use a custom class:

.md-button.md-small {
    min-width: 1%;
}

Or, in Angular Material 2:

.mat-button.mat-small {
    min-width: 1%;
}
Tiago
  • 4,233
  • 13
  • 46
  • 70
23

Try the following class in your styles. You can adjust the pixel depending on how big/small you want the button to be.

.md-button.md-small {
     width: 20px;
     height: 20px;
     line-height: 20px;
     min-height: 20px;
     vertical-align: top;
     font-size: 10px;
     padding: 0 0;
     margin: 0;
}
user1242321
  • 1,578
  • 2
  • 18
  • 30
14

You could use css transform: scale(). You have to play with margins a little bit, but it isn't much code and you can go smaller or bigger pretty easily.

.shrink-2x {
     transform: scale(0.5);
}

.enlarge-2x {
     transform: scale(1.5);
}

Example

tbone849
  • 925
  • 8
  • 18
8

I used this style for making a smaller md-button

button {
    min-height: 23px !important;
    min-width: 46px !important;
    font-size: 10px !important;
    line-height: 0px; 
}
Sameeksha Kumari
  • 1,158
  • 2
  • 16
  • 21
3

I'm using https://github.com/angular/material2

this creates smaller mini-fab.

enter image description here

.del {
  width: 30px;
  height: 30px;
}

.del .mat-icon {
    padding: 4px 0;
    line-height: 22px;
}
<button md-mini-fab (click)="onDeleteValue(valIndex)"
        type="button"
        color="warn"
        class="del">
    <md-icon>close</md-icon>
</button>
Nabil.A
  • 581
  • 4
  • 16
2

I found that font-size must be on md-icon, and I needed a min-height on both the md-button and md-icon tags.

<md-button
    class="md-exclude
    md-icon-button
    md-primary"
    style="margin-right:0;
    padding:0; height:20px;
    min-height:1px;"
    ng-click="openfn($event, newnote)"
    aria-label="note">
    <md-icon
        class="material-icons"
        style="font-size:20px;
        min-height:1px;">
        info_outline
    </md-icon>
    <md-tooltip md-direction="top">
        {[{ ::tooltiplabel }]}
    </md-tooltip>
</md-button>
Brendan Metcalfe
  • 753
  • 10
  • 10
1

Many answers here have superfluous CSS properties used. This is all you need:

.my-mat-button {
  line-height: 1;
  min-width: 0;
  padding: 7px 15px 5px; // adjust as needed
}

you may also want to (or not) tweak font-size and border-radius but that goes without saying.

danday74
  • 52,471
  • 49
  • 232
  • 283
0

If you are using md-icon-button, then material sets a width, height and padding for the icon:

.md-button.md-icon-button {
   margin: 0 6px;
   height: 40px;
   min-width: 0;
   line-height: 24px;
   padding: 8px;
   width: 40px;
   border-radius: 50%;
}

so you need to override it ("auto" works well if you want the button to fit the parent)

.md-button.md-small {
    padding: 0px;
    margin: 0px;
    height: auto;
    width: auto;
    min-height: 20px;
}
0

Tiago's answer worked for me.

If you are using variants of mat buttons , raised button for example -

.mat-raised-button {
    min-width: 150px;
}
Akshaya
  • 1
  • 1
-1

Simply add .mat-small (for Angular Material 2+) to the Button's classes and no custom styles needed.

For Angular Material

<button
  mat-button
  class="mat-small"
</button>