While using angular material radio buttons, I wanted to make them in 2 directions -> 2 at the left of the screen and 2 at the rightmost of the screen. I am using the mat-radio-button to accomplish this. Attaching the lines of code below, Using this code i have got the buttons on the left, want to position a few more on the right like the image attached below. Code Explanation - Inside an accordion I have 4 radio button options of which I want to position 2 at the left and 2 at right most.
<mat-accordion>
<mat-expansion-panel [expanded]="step === 0" (opened)="setStep(0)">
<mat-expansion-panel-header>
<h3 class="m-portlet__head-text">
Basic Details
</h3>
</mat-expansion-panel-header>
<div class="m-form m-form--fit m-form--label-align-right m-form--group-seperator">
<div class="m-portlet__body">
<div class="form-group m-form__group row">
<div class="m-radio-list">
<mat-radio-group class="example-radio-group" (change)="changeComboo($event)" [(ngModel)]="choosePolicyType">
<p>
<mat-radio-button class="example-radio-button" *ngFor="let pType of policyTypes" [value]="pType">
{{pType}}
</mat-radio-button>
</p>
</mat-radio-group>
</div>
</div>
<div *ngIf="choosePolicyType=='Individual'">
<div class="form-group m-form__group row" >
<div class="col-lg-6">
<mat-form-field appearance="outline">
<mat-label>First Name</mat-label>
<input matInput placeholder="">
</mat-form-field>
<label class="col-lg-2 col-form-label"></label>
<mat-form-field appearance="outline">
<mat-label>Last Name</mat-label>
<input matInput placeholder="">
</mat-form-field>
</div>
</div>
The above being the html->template code and the below attaching the part of the component.ts code where the contents of the radio button defined.
choosePolicyType: string;
policyTypes: string[] = ['Individual','Business'];
Radio button positioning:
You can customise mat-radio-button style as the following:
mat-radio-button:nth-child(2){
margin-right: 40px;
}
This will create a gap between two group of buttons.
CSS:
.mat-radio-group{
display:flex ;
width:100%;
font-size:0.5em;
justify-content: space-between;
}
HTML:
<mat-radio-group class="myGroup">
<span class="group1">
<mat-radio-button value="1">Option 1</mat-radio-button>
<mat-radio-button value="2">Option 2</mat-radio-button>
</span>
<span class="group2">
<mat-radio-button value="3">Option 3</mat-radio-button>
<mat-radio-button value="4">Option 4</mat-radio-button>
</span>
</mat-radio-group>