Adding asterisk to required fields in Bootstrap 3

前端 未结 7 596
粉色の甜心
粉色の甜心 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:17

    Assuming this is what the HTML looks like

    To display an asterisk on the right of the label:

    .form-group.required .control-label:after { 
        color: #d00;
        content: "*";
        position: absolute;
        margin-left: 8px;
        top:7px;
    }
    

    Or to the left of the label:

    .form-group.required .control-label:before{
       color: red;
       content: "*";
       position: absolute;
       margin-left: -15px;
    }
    

    To make a nice big red asterisks you can add these lines:

    font-family: 'Glyphicons Halflings';
    font-weight: normal;
    font-size: 14px;
    

    Or if you are using Font Awesome add these lines (and change the content line):

    font-family: 'FontAwesome';
    font-weight: normal;
    font-size: 14px;
    content: "\f069";
    

提交回复
热议问题