纯CSS实现新拟态风格按钮~
嘿大喵喵
2023年04月23日 12:01
  1. <!DOCTYPE html>  

  2. <html lang="en">  

  3.   

  4. <head>  

  5.     <meta charset="UTF-8">  

  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge">  

  7.     <meta name="viewport" content="width=device-width, initial-scale=1.0">  

  8.     <title>Document</title>  

  9.     <style>  

  10.         body {  

  11.             margin: 0;  

  12.             padding: 0;  

  13.             height: 100vh;  

  14.             display: flex;  

  15.             justify-content: center;  

  16.             align-items: center;  

  17.             background-color: #efeeee;  

  18.             gap: 30px;  

  19.         }  

  20.   

  21.         img {  

  22.             width: 60px;  

  23.         }  

  24.   

  25.         .img {  

  26.             width: 100px;  

  27.             height: 100px;  

  28.             display: flex;  

  29.             justify-content: center;  

  30.             align-items: center;  

  31.             border-radius: 20px;  

  32.             box-shadow: 18px 18px 30px rgba(0, 0, 0, 0.2),  

  33.                 -18px -18px 30px rgba(255, 255, 255, 1);  

  34.             transition: all 0.2s ease-in-out;  

  35.         }  

  36.   

  37.         .img:hover {  

  38.             cursor: pointer;  

  39.             box-shadow: 0 0 0 rgba(0, 0, 0, 0.2),  

  40.                 0 0 0 rgba(255, 255, 255, 0.8),  

  41.                 inset 18px 18px 30px rgba(0, 0, 0, 0.1),  

  42.                 inset -18px -18px 30px rgba(255, 255, 255, 1);  

  43.         }  

  44.   

  45.         .img:hover img {  

  46.             width: 58px;  

  47.         }  

  48.     </style>  

  49. </head>  

  50.   

  51. <body>  

  52.     <div class="img">  

  53.         <img src="https://iconfont.alicdn.com/p/illus_3d/preview_image/gOUqAFa0J5Zz/4ce8471f-7131-45ce-bba5-a94d3dbb875a.png"  

  54.             alt="">  

  55.     </div>  

  56.   

  57.     <div class="img">  

  58.         <img src="https://iconfont.alicdn.com/p/illus_3d/preview_image/gOUqAFa0J5Zz/2b28bb4d-f7e1-44fb-bfb0-c0d8c4b7e8ad.png"  

  59.             alt="">  

  60.     </div>  

  61.     <div class="img">  

  62.         <img src="https://iconfont.alicdn.com/p/illus_3d/preview_image/gOUqAFa0J5Zz/acbb34c3-c890-4394-ac07-f7fb87a68abe.png"  

  63.             alt="">  

  64.     </div>  

  65.     <div class="img">  

  66.         <img src="https://iconfont.alicdn.com/p/illus_3d/preview_image/gOUqAFa0J5Zz/cb9b62f6-342f-4817-94c8-cc2dc93d7ed5.png"  

  67.             alt="">  

  68.     </div>  

  69.     <div class="img">  

  70.         <img src="https://iconfont.alicdn.com/p/illus_3d/preview_image/gOUqAFa0J5Zz/ac407164-ab17-4cc3-8917-dd6472620667.png"  

  71.             alt="">  

  72.     </div>  

  73. </body>  

  74.   

  75. </html>