Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ng-valid[required], .ng-valid.required?

Tags:

css

angular

I was going through https://angular.io/docs/ts/latest/guide/forms.html as exercise then I came through this piece of code:

.ng-valid[required], .ng-valid.required  {
  border-left: 5px solid #42A948; /* green */
}

.ng-invalid:not(form)  {
  border-left: 5px solid #a94442; /* red */
}

Why are both of .ng-valid[required], .ng-valid.required selectors used at the same time and cant we just replace this by only one of them?

like image 478
Sarah cartenz Avatar asked Dec 08 '16 07:12

Sarah cartenz


1 Answers

The .ng-valid[required] rule is valid for

<input class="ng-valid" required>

The .ng-valid.required rule is valid for

<input class="ng-valid required">

Both rules are valid for

<input class="ng-valid required" required>

Now you can choose which solution you want to use and remove the not necessary rules on your CSS.

like image 185
Sebastian Brosch Avatar answered Nov 09 '22 06:11

Sebastian Brosch