test.css 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*开关的大小*/
  2. .switch-container {
  3. height: 25px;
  4. width: 60px;
  5. margin-left: 150px;
  6. margin-top: -23px;
  7. }
  8. /*设置checkbox不显示*/
  9. .switch {
  10. display: none;
  11. }
  12. /*设置label标签为椭圆状*/
  13. label {
  14. display: block;
  15. background-color: #EEEEEE;
  16. height: 100%;
  17. width: 100%;
  18. cursor: pointer;
  19. border-radius: 25px;
  20. }
  21. /*在label标签内容之前添加如下样式,形成一个未选中状态*/
  22. label:before {
  23. content: '';
  24. display: block;
  25. border-radius: 25px;
  26. height: 100%;
  27. width: 24px;
  28. background-color: white;
  29. opacity: 1;
  30. box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, 0.08);
  31. -webkit-transition: all 0.2s ease;
  32. }
  33. /*在label标签内容之后添加如下样式,形成一个选中状态*/
  34. label:after {
  35. position: relative;
  36. top: -25px;
  37. left: 36px;
  38. content: '';
  39. display: block;
  40. border-radius: 25px;
  41. height: 100%;
  42. width: 24px;
  43. background-color: white;
  44. opacity: 0;
  45. box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, 0.08);
  46. -webkit-transition: all 0.2s ease;
  47. }
  48. /* ~ 兄弟选择符。
  49. p~ul :位于 p 元素之后的所有 ul 元素
  50. */
  51. /*选中后,选中样式显示*/
  52. #switch:checked~label:after {
  53. opacity: 1;
  54. }
  55. /*选中后,未选中样式消失*/
  56. #switch:checked~label:before {
  57. opacity: 0;
  58. }
  59. /*选中后label的背景色改变*/
  60. #switch:checked~label {
  61. background-color: green;
  62. }