当前位置:   article > 正文

分享几个精美的网页按钮样式,纯CSS实现,无JS(拿来即用)_css按钮样式简约

css按钮样式简约

点击按钮

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title></title>
  5. <style>
  6. button {
  7. position: relative;
  8. display: inline-block;
  9. cursor: pointer;
  10. outline: none;
  11. border: 0;
  12. vertical-align: middle;
  13. text-decoration: none;
  14. font-family: inherit;
  15. font-size: 15px;
  16. }
  17. button.learn-more {
  18. font-weight: 600;
  19. color: #382b22;
  20. text-transform: uppercase;
  21. padding: 1.25em 2em;
  22. background: #fff0f0;
  23. border: 2px solid #727bb1;
  24. border-radius: 0.75em;
  25. -webkit-transform-style: preserve-3d;
  26. transform-style: preserve-3d;
  27. -webkit-transition: background 150ms cubic-bezier(0, 0, 0.58, 1), -webkit-transform 150ms cubic-bezier(0, 0, 0.58, 1);
  28. transition: transform 150ms cubic-bezier(0, 0, 0.58, 1), background 150ms cubic-bezier(0, 0, 0.58, 1), -webkit-transform 150ms cubic-bezier(0, 0, 0.58, 1);
  29. }
  30. button.learn-more::before {
  31. position: absolute;
  32. content: '';
  33. width: 100%;
  34. height: 100%;
  35. top: 0;
  36. left: 0;
  37. right: 0;
  38. bottom: 0;
  39. background: #c6ccf9;
  40. border-radius: inherit;
  41. -webkit-box-shadow: 0 0 0 2px #727bb1, 0 0.625em 0 0 #ffe3e2;
  42. box-shadow: 0 0 0 2px #727bb1, 0 0.625em 0 0 #ffe3e2;
  43. -webkit-transform: translate3d(0, 0.75em, -1em);
  44. transform: translate3d(0, 0.75em, -1em);
  45. transition: transform 150ms cubic-bezier(0, 0, 0.58, 1), box-shadow 150ms cubic-bezier(0, 0, 0.58, 1), -webkit-transform 150ms cubic-bezier(0, 0, 0.58, 1), -webkit-box-shadow 150ms cubic-bezier(0, 0, 0.58, 1);
  46. }
  47. button.learn-more:hover {
  48. background: #ffe4ce;
  49. -webkit-transform: translate(0, 0.25em);
  50. transform: translate(0, 0.25em);
  51. }
  52. button.learn-more:hover::before {
  53. -webkit-box-shadow: 0 0 0 2px #727bb1, 0 0.5em 0 0 #ffe3e2;
  54. box-shadow: 0 0 0 2px #727bb1, 0 0.5em 0 0 #ffe3e2;
  55. -webkit-transform: translate3d(0, 0.5em, -1em);
  56. transform: translate3d(0, 0.5em, -1em);
  57. }
  58. button.learn-more:active {
  59. background: #ffe4ce;
  60. -webkit-transform: translate(0em, 0.75em);
  61. transform: translate(0em, 0.75em);
  62. }
  63. button.learn-more:active::before {
  64. -webkit-box-shadow: 0 0 0 2px #727bb1, 0 0 #d1cbff;
  65. box-shadow: 0 0 0 2px #727bb1, 0 0 #d1cbff;
  66. -webkit-transform: translate3d(0, 0, -1em);
  67. transform: translate3d(0, 0, -1em);
  68. }
  69. </style>
  70. </head>
  71. <body>
  72. <button class="learn-more">> w <;;;</button>
  73. </body>
  74. </html>

效果:

凹陷效果

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title></title>
  5. <style>
  6. body{
  7. background-color: #f0f0f0;
  8. }
  9. button {
  10. color: #090909;
  11. padding: 0.7em 1.7em;
  12. font-size: 18px;
  13. border-radius: 0.5em;
  14. background: #e8e8e8;
  15. border: 1px solid #e8e8e8;
  16. transition: all .3s;
  17. box-shadow: 6px 6px 12px #c5c5c5,
  18. -6px -6px 12px #ffffff;
  19. }
  20. button:active {
  21. color: #666;
  22. box-shadow: inset 4px 4px 12px #c5c5c5,
  23. inset -4px -4px 12px #ffffff;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <button>T____T</button>
  29. </body>
  30. </html>

效果:

开关按钮

  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title></title>
  5. <style>
  6. /* 开关:滑块周围的盒子 */
  7. .switch {
  8. font-size: 17px;
  9. position: relative;
  10. display: inline-block;
  11. width: 3.5em;
  12. height: 2em;
  13. }
  14. /* 隐藏默认的HTML复选框 */
  15. .switch input {
  16. opacity: 0;
  17. width: 0;
  18. height: 0;
  19. }
  20. /* 滑块 */
  21. .slider {
  22. position: absolute;
  23. cursor: pointer;
  24. top: 0;
  25. left: 0;
  26. right: 0;
  27. bottom: 0;
  28. background-color: #B0B0B0;
  29. border: 1px solid #B0B0B0;
  30. transition: .4s;
  31. border-radius: 32px;
  32. outline: none;
  33. }
  34. .slider:before {
  35. position: absolute;
  36. content: "";
  37. height: 2rem;
  38. width: 2rem;
  39. border-radius: 50%;
  40. outline: 2px solid #B0B0B0;
  41. left: -1px;
  42. bottom: -1px;
  43. background-color: #fff;
  44. transition: transform .25s ease-in-out 0s;
  45. }
  46. .slider-icon {
  47. opacity: 0;
  48. height: 12px;
  49. width: 12px;
  50. stroke-width: 8;
  51. position: absolute;
  52. z-index: 999;
  53. stroke: #222222;
  54. right: 60%;
  55. top: 30%;
  56. transition: right ease-in-out .3s, opacity ease-in-out .15s;
  57. }
  58. input:checked + .slider {
  59. background-color: #222222;
  60. }
  61. input:checked + .slider .slider-icon {
  62. opacity: 1;
  63. right: 20%;
  64. }
  65. input:checked + .slider:before {
  66. transform: translateX(1.5em);
  67. outline-color: #181818;
  68. }
  69. </style>
  70. </head>
  71. <body>
  72. <label class="switch">
  73. <input type="checkbox">
  74. <span class="slider">
  75. <svg class="slider-icon" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="presentation"><path fill="none" d="m4 16.5 8 8 16-16"></path></svg>
  76. </span>
  77. </label>
  78. </body>
  79. </html>

效果:

谢谢大家观看,T________T

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号