Adding asterisk to required fields in Bootstrap 3

前端 未结 7 599
粉色の甜心
粉色の甜心 2021-01-29 17:56

My HTML has a class called .required that is assigned to required fields.

Here is the HTML:

7条回答
  •  野的像风
    2021-01-29 18:18

    Use .form-group.required without the space.

    .form-group.required .control-label:after {
      content:"*";
      color:red;
    }
    

    Edit:

    For the checkbox you can use the pseudo class :not(). You add the required * after each label unless it is a checkbox

    .form-group.required:not(.checkbox) .control-label:after, 
    .form-group.required .text:after { /* change .text in whatever class of the text after the checkbox has */
       content:"*";
       color:red;
    }
    

    Note: not tested

    You should use the .text class or target it otherwise probably, try this html:

    Ok third edit:

    CSS back to what is was

    .form-group.required .control-label:after { 
       content:"*";
       color:red;
    }
    

    HTML:

提交回复
热议问题