I have an application that is AngularJS and Bootstrap, although I am not sure if it is relevant. I want to define CSS style for required fields. I see many examples if the field has class='required'
, for example here:
.form-group.required .control-label:after {
content:"*";
color:red;
}
However, is it possible to do the same if the field has required='required'
, but doesn't have required
class?
As a practical matter, I have a field that is conditionally required using ng-required='chkChecked'
and while I can also add ng-class={'required': chkChecked}
I would prefer to avoid it if possible
Update just to clarify - I want to style the field if it has "required" attribute regardless whether it has required
class. My initial question could be interpreted that I want to style the element if it is required, but doesn't have required class. That's not the case. Sorry.
Also, I would prefer to put an asterisk on the label attached to the input field, rather than, say, a red border attached to the field itself (which can be accomplished by input[:required]
(that I didn't know about). I did try .form-group:required
, but for some reason it doesn't do anything, although I see <div class="form-group" required="required">
in F12