经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » CSS3 » 查看文章
CSS3 制作的彩虹按钮样式_css3_CSS
来源:jb51  时间:2021/4/12 9:34:50  对本文有异议

实现效果:

实现代码:

html

  1. <div class="buttons">
  2. <h1>Simple hover effects with <code>box-shadow</code></h1>
  3. <button class="fill">Fill In</button>
  4. <button class="pulse">Pulse</button>
  5. <button class="close">Close</button>
  6. <button class="raise">Raise</button>
  7. <button class="up">Fill Up</button>
  8. <button class="slide">Slide</button>
  9. <button class="offset">Offset</button>
  10. </div>

CSS

  1. /*
  2. https://developer.mozilla.org/en/docs/Web/CSS/box-shadow
  3. box-shadow: [inset?] [top] [left] [blur] [size] [color];
  4.  
  5. Tips:
  6. - We're setting all the blurs to 0 since we want a solid fill.
  7. - Add the inset keyword so the box-shadow is on the inside of the element
  8. - Animating the inset shadow on hover looks like the element is filling in from whatever side you specify ([top] and [left] accept negative values to become [bottom] and [right])
  9. - Multiple shadows can be stacked
  10. - If you're animating multiple shadows, be sure to keep the same number of shadows so the animation is smooth. Otherwise, you'll get something choppy.
  11. */
  12. .fill:hover,
  13. .fill:focus {
  14. box-shadow: inset 0 0 0 2em var(--hover);
  15. }
  16.  
  17. .pulse:hover,
  18. .pulse:focus {
  19. -webkit-animation: pulse 1s;
  20. animation: pulse 1s;
  21. box-shadow: 0 0 0 2em rgba(255, 255, 255, 0);
  22. }
  23.  
  24. @-webkit-keyframes pulse {
  25. 0% {
  26. box-shadow: 0 0 0 0 var(--hover);
  27. }
  28. }
  29.  
  30. @keyframes pulse {
  31. 0% {
  32. box-shadow: 0 0 0 0 var(--hover);
  33. }
  34. }
  35. .close:hover,
  36. .close:focus {
  37. box-shadow: inset -3.5em 0 0 0 var(--hover), inset 3.5em 0 0 0 var(--hover);
  38. }
  39.  
  40. .raise:hover,
  41. .raise:focus {
  42. box-shadow: 0 0.5em 0.5em -0.4em var(--hover);
  43. transform: translateY(-0.25em);
  44. }
  45.  
  46. .up:hover,
  47. .up:focus {
  48. box-shadow: inset 0 -3.25em 0 0 var(--hover);
  49. }
  50.  
  51. .slide:hover,
  52. .slide:focus {
  53. box-shadow: inset 6.5em 0 0 0 var(--hover);
  54. }
  55.  
  56. .offset {
  57. box-shadow: 0.3em 0.3em 0 0 var(--color), inset 0.3em 0.3em 0 0 var(--color);
  58. }
  59. .offset:hover, .offset:focus {
  60. box-shadow: 0 0 0 0 var(--hover), inset 6em 3.5em 0 0 var(--hover);
  61. }
  62.  
  63. .fill {
  64. --color: #a972cb;
  65. --hover: #cb72aa;
  66. }
  67.  
  68. .pulse {
  69. --color: #ef6eae;
  70. --hover: #ef8f6e;
  71. }
  72.  
  73. .close {
  74. --color: #ff7f82;
  75. --hover: #ffdc7f;
  76. }
  77.  
  78. .raise {
  79. --color: #ffa260;
  80. --hover: #e5ff60;
  81. }
  82.  
  83. .up {
  84. --color: #e4cb58;
  85. --hover: #94e458;
  86. }
  87.  
  88. .slide {
  89. --color: #8fc866;
  90. --hover: #66c887;
  91. }
  92.  
  93. .offset {
  94. --color: #19bc8b;
  95. --hover: #1973bc;
  96. }
  97.  
  98. button {
  99. color: var(--color);
  100. transition: 0.25s;
  101. }
  102. button:hover, button:focus {
  103. border-color: var(--hover);
  104. color: #fff;
  105. }
  106.  
  107. body {
  108. color: #fff;
  109. background: #17181c;
  110. font: 300 1em "Fira Sans", sans-serif;
  111. justify-content: center;
  112. align-content: center;
  113. align-items: center;
  114. text-align: center;
  115. min-height: 100vh;
  116. display: flex;
  117. }
  118.  
  119. button {
  120. background: none;
  121. border: 2px solid;
  122. font: inherit;
  123. line-height: 1;
  124. margin: 0.5em;
  125. padding: 1em 2em;
  126. }
  127.  
  128. h1 {
  129. font-weight: 400;
  130. }
  131.  
  132. code {
  133. color: #e4cb58;
  134. font: inherit;
  135. }

以上就是CSS3 制作的彩虹按钮样式的详细内容,更多关于CSS3 按钮样式的资料请关注w3xue其它相关文章!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号