How to style a checkbox using CSS

前端 未结 30 3522
日久生厌
日久生厌 2020-11-21 04:26

I am trying to style a checkbox using the following:

30条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-21 05:22

    Simple to implement and easily customizable solution

    After a lot of search and testing I got this solution which is simple to implement and easier to customize. In this solution:

    1. You don't need external libraries and files
    2. You don't need to add extra HTML in your page
    3. You don't need to change checkbox names and id

    Simple put the flowing CSS at the top of your page and all checkboxes style will change like this:

    input[type=checkbox] {
      transform: scale(1.5);
    }
    
    input[type=checkbox] {
      width: 30px;
      height: 30px;
      margin-right: 8px;
      cursor: pointer;
      font-size: 17px;
      visibility: hidden;
    }
    
    input[type=checkbox]:after {
      content: " ";
      background-color: #fff;
      display: inline-block;
      margin-left: 10px;
      padding-bottom: 5px;
      color: #00BFF0;
      width: 22px;
      height: 25px;
      visibility: visible;
      border: 1px solid #00BFF0;
      padding-left: 3px;
      border-radius: 5px;
    }
    
    input[type=checkbox]:checked:after {
      content: "\2714";
      padding: -5px;
      font-weight: bold;
    }
    
    

提交回复
热议问题