Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material Design : Radio button group to be vertically aligned

Below is the angular material code i am using to display radio buttons :

<div>
    <mat-radio-group>
        <mat-radio-button value="1">Transcription</mat-radio-button>
        <mat-radio-button value="2">Summarization</mat-radio-button>
        <mat-radio-button value="3">Both</mat-radio-button>
    </mat-radio-group>
</div>

But this is displaying the radiobuttons horizontally. But i need them to be displayed vertically.

like image 464
Rpcoder Avatar asked Jul 07 '19 21:07

Rpcoder


People also ask

How to use radio button in angular Material?

Radio-buttons should typically be placed inside of an <mat-radio-group> unless the DOM structure would make that impossible (e.g., radio-buttons inside of table cells). The radio-group has a value property that reflects the currently selected radio-button inside of the group.


2 Answers

You can use CSS to get this done, add a class to your mat-radio-group where you can use:

  • display: flex; flex-direction: column;
  • or display: grid;
  • or display: inline-grid;

relevant HTML:

<div>
    <mat-radio-group class="example-radio-group">
        <mat-radio-button value="1">Transcription</mat-radio-button>
        <mat-radio-button value="2">Summarization</mat-radio-button>
        <mat-radio-button value="3">Both</mat-radio-button>
    </mat-radio-group>
</div>

relevant CSS:

.example-radio-group {
  display: flex; flex-direction: column;
  /* display: inline-grid; */ 
  /* display: grid; */
  margin: 15px 0;
}

working stackblitz here

like image 97
Akber Iqbal Avatar answered Sep 21 '22 11:09

Akber Iqbal


Simply add a <br> tag after each <mat-radio-button>

like image 26
CaffeinatedCod3r Avatar answered Sep 19 '22 11:09

CaffeinatedCod3r