image.png
image.png

  1. input[type="checkbox"]+label::before {
  2. content: '\a0';
  3. background: silver;
  4. /* content: '\2713';
  5. background: yellowgreen; */
  6. /* 不换行空格 */
  7. display: inline-block;
  8. vertical-align: .2em;
  9. width: .8em;
  10. height: .8em;
  11. margin-right: .2em;
  12. border-radius: .2em;
  13. text-indent: .15em;
  14. line-height: .65;
  15. }
  1. 隐藏原来的复选框
  2. input[type="checkbox"] {
  3. position: absolute;
  4. clip: rect(0, 0, 0, 0);
  5. }

在它聚焦或禁用时改变它的样式

  1. input[type="checkbox"]:focus + label::before {
  2. box-shadow: 0 0 .1em .1em #58a;
  3. }
  4. input[type="checkbox"]:disabled + label::before {
  5. background: gray; box-shadow: none; color: #555;
  6. }

开关式按钮

s.gif

  1. input[type="checkbox"] {
  2. position: absolute;
  3. clip: rect(0, 0, 0, 0);
  4. }
  5. input[type="checkbox"]+label {
  6. display: inline-block;
  7. padding: .3em .5em;
  8. background: #ccc;
  9. background-image: linear-gradient(#ddd, #bbb);
  10. border: 1px solid rgba(0, 0, 0, .2);
  11. border-radius: .3em;
  12. box-shadow: 0 1px white inset;
  13. text-align: center;
  14. text-shadow: 0 1px 1px white;
  15. }
  16. input[type="checkbox"]:checked+label,
  17. input[type="checkbox"]:active+label {
  18. box-shadow: .05em .1em .2em rgba(0, 0, 0, .6) inset;
  19. border-color: rgba(0, 0, 0, .3);
  20. background: #bbb;
  21. }
  22. <input type="checkbox" id="awesome" />
  23. <label for="awesome">Awesome!</label>