爬行的蜗牛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: golang Linux PHP
查看: 105|回复: 0

前端纯CSS特效丨新型选中特效(开关)

[复制链接]

152

主题

48

回帖

1137

积分

管理员

积分
1137
发表于 2024-12-22 20:33:20 | 显示全部楼层 |阅读模式

640.gif

HTML:

  1. <label class="container">
  2.   <div class="simple-text">Click me!</div>
  3.   <input checked="checked" type="checkbox" />
  4.   <div class="checkmark"></div>
  5.   <div class="torch">
  6.     <div class="head">
  7.       <div class="face top">
  8.         <div></div>
  9.         <div></div>
  10.         <div></div>
  11.         <div></div>
  12.       </div>
  13.       <div class="face left">
  14.         <div></div>
  15.         <div></div>
  16.         <div></div>
  17.         <div></div>
  18.       </div>
  19.       <div class="face right">
  20.         <div></div>
  21.         <div></div>
  22.         <div></div>
  23.         <div></div>
  24.       </div>
  25.     </div>
  26.     <div class="stick">
  27.       <div class="side side-left">
  28.         <div></div>
  29.         <div></div>
  30.         <div></div>
  31.         <div></div>
  32.         <div></div>
  33.         <div></div>
  34.         <div></div>
  35.         <div></div>
  36.         <div></div>
  37.         <div></div>
  38.         <div></div>
  39.         <div></div>
  40.         <div></div>
  41.         <div></div>
  42.         <div></div>
  43.         <div></div>
  44.       </div>
  45.       <div class="side side-right">
  46.         <div></div>
  47.         <div></div>
  48.         <div></div>
  49.         <div></div>
  50.         <div></div>
  51.         <div></div>
  52.         <div></div>
  53.         <div></div>
  54.         <div></div>
  55.         <div></div>
  56.         <div></div>
  57.         <div></div>
  58.         <div></div>
  59.         <div></div>
  60.         <div></div>
  61.         <div></div>
  62.       </div>
  63.     </div>
  64.   </div>
  65. </label>
复制代码
CSS:
  1. .container input {
  2.   position: absolute;
  3.   opacity: 0;
  4.   cursor: pointer;
  5.   height: 0;
  6.   width: 0;
  7. }

  8. .container {
  9.   display: flex;
  10.   flex-direction: column;
  11.   align-items: center;
  12.   position: relative;
  13.   cursor: pointer;
  14.   user-select: none;
  15. }

  16. .simple-text {
  17.   position: absolute;
  18.   bottom: -40px;
  19.   width: 120px;
  20.   text-align: center;
  21.   color: white;
  22.   font-size: 16pt;
  23.   font-weight: 800;
  24.   font-family: monospace;
  25. }

  26. .torch {
  27.   display: flex;
  28.   justify-content: center;
  29.   height: 150px;
  30. }

  31. .head,
  32. .stick {
  33.   position: absolute;
  34.   width: 30px;
  35.   transform-style: preserve-3d;
  36.   transform: rotateX(-30deg) rotateY(45deg);
  37. }

  38. .stick {
  39.   position: relative;
  40.   height: 120px;
  41. }

  42. .face {
  43.   position: absolute;
  44.   transform-style: preserve-3d;
  45.   width: 30px;
  46.   height: 30px;
  47.   display: grid;
  48.   grid-template-columns: 50% 50%;
  49.   grid-template-rows: 50% 50%;
  50.   background-color: #000000;
  51. }

  52. .top {
  53.   transform: rotateX(90deg) translateZ(15px);
  54. }

  55. .left {
  56.   transform: rotateY(-90deg) translateZ(15px);
  57. }

  58. .right {
  59.   transform: rotateY(0deg) translateZ(15px);
  60. }

  61. .top div,
  62. .left div,
  63. .right div {
  64.   width: 102%;
  65.   height: 102%;
  66. }

  67. .top div:nth-child(1),
  68. .left div:nth-child(3),
  69. .right div:nth-child(3) {
  70.   background-color: #ffff9760;
  71. }

  72. .top div:nth-child(2),
  73. .left div:nth-child(1),
  74. .right div:nth-child(1) {
  75.   background-color: #ffd80060;
  76. }

  77. .top div:nth-child(3),
  78. .left div:nth-child(4),
  79. .right div:nth-child(4) {
  80.   background-color: #ffffff60;
  81. }

  82. .top div:nth-child(4),
  83. .left div:nth-child(2),
  84. .right div:nth-child(2) {
  85.   background-color: #ff8f0060;
  86. }

  87. .side {
  88.   position: absolute;
  89.   width: 30px;
  90.   height: 120px;
  91.   display: grid;
  92.   grid-template-columns: 50% 50%;
  93.   grid-template-rows: repeat(8, 12.5%);
  94.   cursor: pointer;
  95.   translate: 0 12px;
  96. }

  97. .side-left {
  98.   transform: rotateY(-90deg) translateZ(15px) translateY(8px);
  99. }

  100. .side-right {
  101.   transform: rotateY(0deg) translateZ(15px) translateY(8px);
  102. }

  103. .side-left div,
  104. .side-right div {
  105.   width: 103%;
  106.   height: 103%;
  107. }

  108. .side div:nth-child(1) {
  109.   background-color: #443622;
  110. }

  111. .side div:nth-child(2),
  112. .side div:nth-child(2) {
  113.   background-color: #2e2517;
  114. }

  115. .side div:nth-child(3),
  116. .side div:nth-child(5) {
  117.   background-color: #4b3b23;
  118. }

  119. .side div:nth-child(4),
  120. .side div:nth-child(10) {
  121.   background-color: #251e12;
  122. }

  123. .side div:nth-child(6) {
  124.   background-color: #292115;
  125. }

  126. .side div:nth-child(7) {
  127.   background-color: #4b3c26;
  128. }

  129. .side div:nth-child(8) {
  130.   background-color: #292115;
  131. }

  132. .side div:nth-child(9) {
  133.   background-color: #4b3a21;
  134. }

  135. .side div:nth-child(11),
  136. .side div:nth-child(15) {
  137.   background-color: #3d311d;
  138. }

  139. .side div:nth-child(12) {
  140.   background-color: #2c2315;
  141. }

  142. .side div:nth-child(13) {
  143.   background-color: #493a22;
  144. }

  145. .side div:nth-child(14) {
  146.   background-color: #2b2114;
  147. }

  148. .side div:nth-child(16) {
  149.   background-color: #271e10;
  150. }

  151. .container input:checked ~ .torch .face {
  152.   filter: drop-shadow(0px 0px 2px rgb(255, 255, 255))
  153.     drop-shadow(0px 0px 10px rgba(255, 237, 156, 0.7))
  154.     drop-shadow(0px 0px 25px rgba(255, 227, 101, 0.4));
  155. }

  156. .container input:checked ~ .torch .top div:nth-child(1),
  157. .container input:checked ~ .torch .left div:nth-child(3),
  158. .container input:checked ~ .torch .right div:nth-child(3) {
  159.   background-color: #ffff97;
  160. }

  161. .container input:checked ~ .torch .top div:nth-child(2),
  162. .container input:checked ~ .torch .left div:nth-child(1),
  163. .container input:checked ~ .torch .right div:nth-child(1) {
  164.   background-color: #ffd800;
  165. }

  166. .container input:checked ~ .torch .top div:nth-child(3),
  167. .container input:checked ~ .torch .left div:nth-child(4),
  168. .container input:checked ~ .torch .right div:nth-child(4) {
  169.   background-color: #ffffff;
  170. }

  171. .container input:checked ~ .torch .top div:nth-child(4),
  172. .container input:checked ~ .torch .left div:nth-child(2),
  173. .container input:checked ~ .torch .right div:nth-child(2) {
  174.   background-color: #ff8f00;
  175. }

  176. .container input:checked ~ .torch .side div:nth-child(1) {
  177.   background-color: #7c623e;
  178. }

  179. .container input:checked ~ .torch .side div:nth-child(2),
  180. .container input:checked ~ .torch .side div:nth-child(2) {
  181.   background-color: #4c3d26;
  182. }

  183. .container input:checked ~ .torch .side div:nth-child(3),
  184. .container input:checked ~ .torch .side div:nth-child(5) {
  185.   background-color: #937344;
  186. }

  187. .container input:checked ~ .torch .side div:nth-child(4),
  188. .container input:checked ~ .torch .side div:nth-child(10) {
  189.   background-color: #3c2f1c;
  190. }

  191. .container input:checked ~ .torch .side div:nth-child(6) {
  192.   background-color: #423522;
  193. }

  194. .container input:checked ~ .torch .side div:nth-child(7) {
  195.   background-color: #9f7f50;
  196. }

  197. .container input:checked ~ .torch .side div:nth-child(8) {
  198.   background-color: #403320;
  199. }

  200. .container input:checked ~ .torch .side div:nth-child(9) {
  201.   background-color: #977748;
  202. }

  203. .container input:checked ~ .torch .side div:nth-child(11),
  204. .container input:checked ~ .torch .side div:nth-child(15) {
  205.   background-color: #675231;
  206. }

  207. .container input:checked ~ .torch .side div:nth-child(12) {
  208.   background-color: #3d301d;
  209. }

  210. .container input:checked ~ .torch .side div:nth-child(13) {
  211.   background-color: #987849;
  212. }

  213. .container input:checked ~ .torch .side div:nth-child(14) {
  214.   background-color: #3b2e1b;
  215. }

  216. .container input:checked ~ .torch .side div:nth-child(16) {
  217.   background-color: #372a17;
  218. }
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表