css change the background checkbox

checkbox default background color can not be modified, implemented using a pseudo-earth element, the basic principle is to use after / before inserting new elements. Then take advantage of the new elements of the background color or background image overwrite the original style.

Original appearance

 

To achieve the look

 

<input type="checkbox" />
input[type=checkbox] {
    cursor: pointer;
    position: relative;
  }
  
  input[type=checkbox]:after {
    position: absolute;
    width: 10px;
    height: 10px;
    content: " ";
    background-color: rgb(200,237,255);
    visibility: visible;
    border-top: 1px solid #ccc;
    border-left: 1px solid #ccc;
  }
  
  input[type=checkbox]:checked:after {
    content: "✔";
    position: absolute;
    line-height: 11px;
    left: 0;
    top: 0;
  }

 

 

 

Guess you like

Origin www.cnblogs.com/yuNotes/p/11982183.html