0

If I have three checkboxes in Angular template, like this:

  <mat-checkbox fxFlexFill formControlName="first">  First  </mat-checkbox>
  <mat-checkbox fxFlexFill formControlName="second"> Second </mat-checkbox>
  <mat-checkbox fxFlexFill formControlName="third">  Third  </mat-checkbox>

What would be the correct approach for adding space before the first one, without having to change the template?

I.e. I know I can add a class to the first one, but it feels semantically wrong (perhaps I am wrong of course, but I have a feeling I should be able to do this solely with css), so I was wondering if it was possible to do something similar to inputs, i.e.:

// css
mat-checkbox[name="first"] {
  margin-top: 10px;
}
0

1 Answer 1

3

In your css, change name="first" to formControlName="first" as in your html there is no attribute called name but formControlName.

mat-checkbox[formControlName="first"] {
  margin-top: 10px;
  background-color: red;
}
<mat-checkbox fxFlexFill formControlName="first"> First </mat-checkbox>
<mat-checkbox fxFlexFill formControlName="second"> Second </mat-checkbox>
<mat-checkbox fxFlexFill formControlName="third"> Third </mat-checkbox>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.