Custom checkbox using font awesome and css

前端 未结 2 1843
夕颜
夕颜 2021-01-26 13:21

I\'m making a custom checkbox with font awesome and css.

On click/when checkbox is checked, I trying to create some padding around the black checked box instead(having a

相关标签:
2条回答
  • 2021-01-26 13:43

    You're using a single character so you can't add letter-spacing.

    I'd suggest something like this.

    Reduce the size of the replacement icon/character, add padding and a border. Alternatively, search for a proper icon/character that appears how you want it to be and use that.

    @import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
    
    /*** basic styles ***/
    
    /*** custom checkboxes ***/
    
    input[type=checkbox] {
      display: none;
    }
    /* to hide the checkbox itself */
    
    input[type=checkbox] + label:before {
      font-family: FontAwesome;
    }
    input[type=checkbox] + label:before {
      content: "\f096";
    }
    /* unchecked icon */
    
    /*input[type=checkbox] + label:before { letter-spacing: 10px; }*/
    
    /* space between checkbox and label */
    
    input[type=checkbox]:checked + label:before {
      content: "\f0c8";
      display: inline-block;
    }
    /* checked icon */
    
    input[type=checkbox]:checked + label:before {
      font-size: 60%;
      border: 1px solid black;
      vertical-align: top;
      padding: 2px;
      border-radius: 2px;
    }
    /* allow space for check mark */
    <div>
      <input id="box1" type="checkbox" />
      <label for="box1"></label>
      <br>
      <input id="box2" type="checkbox" />
      <label for="box2"></label>
      <br>
      <input id="box3" type="checkbox" />
      <label for="box3"></label>
    </div>

    0 讨论(0)
  • 2021-01-26 13:52

    Like this?

    @import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
    
    /*** basic styles ***/
    
    /*** custom checkboxes ***/
    
    input[type=checkbox] {
      display: none;
    }
    /* to hide the checkbox itself */
    
    input[type=checkbox] + label:before {
      font-family: FontAwesome;
    }
    input[type=checkbox] + label:before {
      content: "\f096";
    }
    /* unchecked icon */
    
    /*input[type=checkbox] + label:before { letter-spacing: 10px; }*/
    
    /* space between checkbox and label */
    
    input[type=checkbox]:checked + label:before {
      content: "\f0c8";
      font-size:12px;
      margin-left:1px;
    }
    /* checked icon */
    
    input[type=checkbox]:checked + label:before {
      letter-spacing: 5px;
    }
    /* allow space for check mark */
    <div>
      <input id="box1" type="checkbox" />
      <label for="box1"></label>
      <br>
      <input id="box2" type="checkbox" />
      <label for="box2"></label>
      <br>
      <input id="box3" type="checkbox" />
      <label for="box3"></label>
    </div>

    0 讨论(0)
提交回复
热议问题