0

I have two children inside my flex container. The first one is a radio button group and the second one is a text. I would like the text to not exceed the width of the radio button group at any screen size. I do not know how to do it. Can you help me with this? I am sharing the code in stackblitz.

https://stackblitz.com/edit/angular-material-radio-button-demo-faar2f

Following is the html code:

<div class="container">
    <mat-radio-group>
        <mat-radio-button value=1> 1 </mat-radio-button>
        <mat-radio-button value=2> 2 </mat-radio-button>
        <mat-radio-button value=3> 3 </mat-radio-button>
        <mat-radio-button value=4> 4 </mat-radio-button>
        <mat-radio-button value=5> 5 </mat-radio-button>
        <mat-radio-button value=6> 6 </mat-radio-button>
        <mat-radio-button value=7> 7 </mat-radio-button>
        <mat-radio-button value=8> 8 </mat-radio-button>
    </mat-radio-group>
    <div> This is the text content that I would like to always have
          a width lesser than the radio betton button group. 
    </div>
</div>

Following is the css code:

.container {
  display: flex;
  flex-direction: column;
}

Vinay
  • 88
  • 1
  • 10

1 Answers1

1

Output:

enter image description here

I have made the following changes and it seems to work fine:

//app.conponent.html

<div class="container">
    <mat-radio-group class="radioGroup">
        <mat-radio-button class="radio" value=1> 1 </mat-radio-button>
        <mat-radio-button class="radio" value=2> 2 </mat-radio-button>
        <mat-radio-button class="radio" value=3> 3 </mat-radio-button>
        <mat-radio-button class="radio" value=4> 4 </mat-radio-button>
        <mat-radio-button class="radio" value=5> 5 </mat-radio-button>
        <mat-radio-button class="radio" value=6> 6 </mat-radio-button>
        <mat-radio-button class="radio" value=7> 7 </mat-radio-button>
        <mat-radio-button class="radio" value=8> 8 </mat-radio-button>
    </mat-radio-group>
    <p> This is the text content that I would like to always have a width lesser than the radio betton button group.
    </p>
</div>

and css style:

.container {
  display: flex;
  flex: 1;
  flex-direction: column;
  max-width: 480px;
}

.radioGroup {
  display: flex;
  flex-wrap: wrap;
}
p {
  text-align: justify;
}

.radio {
  background-color: yellow;
  min-width: 60px;
  flex: 1;
}

Stackblitz link

Ketan Ramteke
  • 10,183
  • 2
  • 21
  • 41