ios-switch.css 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * iOS 6 style switch checkboxes
  3. * by Lea Verou http://lea.verou.me
  4. */
  5. :root input[type="checkbox"] { /* :root here acting as a filter for older browsers */
  6. position: absolute;
  7. opacity: 0;
  8. }
  9. :root input[type="checkbox"].ios-switch + div {
  10. display: inline-block;
  11. vertical-align: middle;
  12. width: 3em; height: 1em;
  13. border: 1px solid rgba(0,0,0,.3);
  14. border-radius: 999px;
  15. margin: 0 .5em;
  16. background: white;
  17. background-image: linear-gradient(rgba(0,0,0,.1), transparent),
  18. linear-gradient(90deg, hsl(210, 90%, 60%) 50%, transparent 50%);
  19. background-size: 200% 100%;
  20. background-position: 100% 0;
  21. background-origin: border-box;
  22. background-clip: border-box;
  23. overflow: hidden;
  24. transition-duration: .1s;
  25. transition-property: padding, width, background-position, text-indent;
  26. box-shadow: 0 .1em .1em rgba(0,0,0,.2) inset,
  27. 0 .45em 0 .1em rgba(0,0,0,.05) inset;
  28. font-size: 150%; /* change this and see how they adjust! */
  29. }
  30. :root input[type="checkbox"].ios-switch:checked + div {
  31. padding-left: 2em;
  32. /*width: 1em;*/
  33. background-position: 0 0;
  34. }
  35. :root input[type="checkbox"].ios-switch + div:before {
  36. content: '';
  37. float: left;
  38. width: 1.3em;
  39. height: 1.3em;
  40. margin: .15em;
  41. border: 1px solid rgba(0,0,0,.35);
  42. border-radius: inherit;
  43. background: white;
  44. background-image: linear-gradient(rgba(0,0,0,.2), transparent);
  45. box-shadow: 0 .1em .1em .1em hsla(0,0%,100%,.8) inset,
  46. 0 0 .5em rgba(0,0,0,.3);
  47. color: white;
  48. text-shadow: 0 -1px 1px rgba(0,0,0,.3);
  49. text-indent: -2.5em;
  50. }
  51. :root input[type="checkbox"].ios-switch:active + div:before {
  52. background-color: #eee;
  53. }
  54. :root input[type="checkbox"].ios-switch:focus + div {
  55. box-shadow: 0 .1em .1em rgba(0,0,0,.2) inset,
  56. 0 .45em 0 .1em rgba(0,0,0,.05) inset,
  57. 0 0 .4em 1px rgba(255,0,0,.5);
  58. }
  59. :root input[type="checkbox"].ios-switch + div:before,
  60. :root input[type="checkbox"].ios-switch + div:after {
  61. font: bold 60%/1.9 sans-serif;
  62. text-transform: uppercase;
  63. }
  64. :root input[type="checkbox"].ios-switch + div:after {
  65. content: '';
  66. float: left;
  67. text-indent: .5em;
  68. color: rgba(0,0,0,.45);
  69. text-shadow: none;
  70. }
  71. /* Switch code ends here, from now on it’s just bling for the demo page */
  72. body {
  73. padding: 1em;
  74. background: #d2d4dd;
  75. background-image: linear-gradient(90deg, transparent 30%, rgba(0,0,0,.02) 45%, rgba(0,0,0,.02) 55%, transparent 70%);
  76. background-size: 8px 8px;
  77. font: 100%/1.5 sans-serif;
  78. text-shadow: 0 1px 1px white;
  79. }