最近我需要把checkbox做調整
理想狀態大概如這個網站
https://codepen.io/MatthewShields/pen/XgeRWj
由於我會用到AJAX回傳的值做判斷是否要做修改樣式
所以我做成這樣
http://jsfiddle.net/vqm7f1ke/1/
只是目前遇到的問題是,我好像只有大小有改到,顏色卻沒有任何變化
請問這個我該如何修改呢?
瀏覽器原生的 checkbox 實在是又小又醜,大家都想改。
我採用的是另一個,引入 css 檔,然後在每個 checkbox 物件上增加 class 屬性即可。
/* .squaredFour */
.squaredFour {
  width: 24px;
  height: 24px;
  position: relative;
  margin: 20px auto;
  cursor: pointer;
  vertical-align: middle ;
  label {
	vertical-align: middle ;
    width: 24px;
    height: 24px;
    cursor: pointer;
    position: absolute;
    top: 0;
    left: 0;
    background: #fcfff4;
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
    border-radius: 4px;
    box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
    &:after {
      content: '';
      width: 9px;
      height: 5px;
      position: absolute;
      top: 4px;
      left: 4px;
      border: 3px solid #333;
      border-top: none;
      border-right: none;
      background: transparent;
      opacity: 0;
      transform: rotate(-45deg);
    }
    &:hover::after {
      opacity: 0.5;
    }
  }
  input[type=checkbox] {
    visibility: hidden;
    &:checked + label:after {
      opacity: 1;
    }
  }
}
/* end .squaredFour */
效果也不差!
