网页前端设计用CSS制作动画切换开关无需使用JavaScript cid1176源码下载

html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>webIQ</title>
  7. <link rel="stylesheet" href="styles.css">
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  9. </head>
  10. <body>
  11. <div class="container">
  12. <h1>Notifications</h1>
  13. <div class="items">
  14. <label>
  15. <i class="fa fa-envelope-o"></i>
  16. Gmail
  17. </label>
  18. <label class="switch">
  19. <input type="checkbox" checked>
  20. <span class="slider round"></span>
  21. </label>
  22. </div>
  23. <div class="items">
  24. <label>
  25. <i class="fa fa-youtube-play"></i>
  26. YouTube
  27. </label>
  28. <label class="switch">
  29. <input type="checkbox">
  30. <span class="slider round"></span>
  31. </label>
  32. </div>
  33. <div class="items">
  34. <label>
  35. <i class="fa fa-amazon" style="color: black;"></i>
  36. Amazon Shopping
  37. </label>
  38. <label class="switch">
  39. <input type="checkbox">
  40. <span class="slider round"></span>
  41. </label>
  42. </div>
  43. </div>
  44. </body>
  45. </html>
<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>webIQ</title>

 <link rel="stylesheet" href="styles.css">
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>

 <div class="container">
 <h1>Notifications</h1>

 <div class="items">
 <label>
 <i class="fa fa-envelope-o"></i>
 Gmail
 </label>
 <label class="switch">
 <input type="checkbox" checked>
 <span class="slider round"></span>
 </label>
 </div>
 <div class="items">
 <label>
 <i class="fa fa-youtube-play"></i>
 YouTube
 </label>
 <label class="switch">
 <input type="checkbox">
 <span class="slider round"></span>
 </label>
 </div>
 <div class="items">
 <label>
 <i class="fa fa-amazon" style="color: black;"></i>
 Amazon Shopping
 </label>
 <label class="switch">
 <input type="checkbox">
 <span class="slider round"></span>
 </label>
 </div>
 </div>
</body>

</html>

css

  1. @import url("https://fonts.googleapis.com/css?family=Roboto|Poppins&display=swap");
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. }
  6. body {
  7. display: flex;
  8. align-items: center;
  9. justify-content: center;
  10. height: 100vh;
  11. background-color: #33C759;
  12. }
  13. .container {
  14. background-color: #eee;
  15. display: flex;
  16. flex-direction: column;
  17. border-radius: 20px;
  18. height: 300px;
  19. width: 450px;
  20. padding: 20px 30px 30px 30px;
  21. justify-content: space-between;
  22. }
  23. .container h1 {
  24. font-family: "Roboto", sans-serif;
  25. font-size: 45px;
  26. }
  27. .container .items {
  28. font-family: "Poppins", sans-serif;
  29. display: flex;
  30. justify-content: space-between;
  31. align-items: center;
  32. }
  33. .container .items label {
  34. font-size: 30px;
  35. }
  36. .container .items label i {
  37. color: red;
  38. }
  39. .switch {
  40. position: relative;
  41. display: inline-block;
  42. width: 60px;
  43. height: 34px;
  44. }
  45. .switch input {
  46. opacity: 0;
  47. width: 0;
  48. height: 0;
  49. }
  50. .slider {
  51. position: absolute;
  52. cursor: pointer;
  53. top: 0;
  54. left: 0;
  55. right: 0;
  56. bottom: 0;
  57. background-color: #ccc;
  58. transition: 400ms;
  59. }
  60. .slider::before {
  61. position: absolute;
  62. content: "";
  63. height: 26px;
  64. width: 26px;
  65. left: 4px;
  66. bottom: 4px;
  67. background-color: white;
  68. transition: 400ms;
  69. }
  70. input:checked+.slider {
  71. background-color: #33C759;
  72. }
  73. input:focus+.slider {
  74. box-shadow: 0 0 1px #33C759;
  75. }
  76. input:checked+.slider::before {
  77. transform: translateX(26px);
  78. }
  79. .slider.round {
  80. border-radius: 34px;
  81. }
  82. .slider.round::before {
  83. border-radius: 50%;
  84. }
@import url("https://fonts.googleapis.com/css?family=Roboto|Poppins&display=swap");

* {
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-color: #33C759;
}

.container {
  background-color: #eee;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  height: 300px;
  width: 450px;
  padding: 20px 30px 30px 30px;
  justify-content: space-between;
}

.container h1 {
  font-family: "Roboto", sans-serif;
  font-size: 45px;
}

.container .items {
  font-family: "Poppins", sans-serif;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.container .items label {
  font-size: 30px;
}

.container .items label i {
  color: red;
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 400ms;
}

.slider::before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 400ms;
}

input:checked+.slider {
  background-color: #33C759;
}

input:focus+.slider {
  box-shadow: 0 0 1px #33C759;
}

input:checked+.slider::before {
  transform: translateX(26px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round::before {
  border-radius: 50%;
}

 

在线演示


让链接同时具备两种打开方式

获取源码: webIQ - Toggle switch using html and css
下载数:51人次, 文件大小: 1.2 KB, 上传日期: 2021年-12 月-05日

公众号回复:gcode  获取解压密码

qrcode_for_gh_6ea2c28a1709_258 (1)

1,719 人查阅

类似文章