• 炫酷3D按钮


    一.预览


            该样式有一种3D变换的高级感,大家可以合理利用这些样式到自己的按钮上 

    二.代码

    1. 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>3D按钮title>
    7. <style>
    8. /* 通用样式设置,包括盒模型和基础字体 */
    9. * {
    10. box-sizing: border-box;
    11. }
    12. body, html {
    13. height: 100%;
    14. width: 100%;
    15. margin: 0;
    16. font-family: Arial, sans-serif;
    17. overflow: hidden;
    18. }
    19. /* 按钮容器样式,居中显示 */
    20. .container {
    21. width: 680px;
    22. margin: 0 auto;
    23. }
    24. /* 基础按钮样式设置 */
    25. .btn {
    26. border: none;
    27. position: relative;
    28. background: none;
    29. padding: 28px 90px;
    30. text-transform: uppercase;
    31. margin: 30px;
    32. color: inherit;
    33. letter-spacing: 2px;
    34. font-size: 1em;
    35. outline: none;
    36. transition: all 0.4s;
    37. cursor: pointer;
    38. }
    39. /* 3D效果实现前的准备,让该伪元素能够被遮挡*/
    40. .btn::after {
    41. content: "";
    42. position: absolute;
    43. z-index: -1;
    44. transition: all 0.4s;
    45. }
    46. /* 设置3D透视效果 */
    47. .btn-perspective {
    48. perspective: 800px;
    49. display: inline-block;
    50. }
    51. /* 基础3D按钮样式 */
    52. .btn-3d {
    53. transform-style: preserve-3d;
    54. }
    55. /* 第一个按钮的颜色和3D效果设置 */
    56. .btn-one {
    57. background-color: #E74C3C;
    58. }
    59. .btn-one::after {
    60. background-color: #621e16; /* 按钮下方的暗色阴影 */
    61. transform: rotateX(90deg); /* 初始旋转状态 */
    62. }
    63. .btn-one:hover {
    64. transform: rotateX(-45deg); /* 鼠标悬停时的旋转 */
    65. }
    66. /* 其他按钮的样式设置遵循相似的模式,改变颜色和旋转轴 */
    67. /* 第二个按钮样式 */
    68. .btn-two {
    69. background-color: pink;
    70. }
    71. .btn-two::after {
    72. background-color: rgb(130, 56, 69);
    73. transform: rotateX(-90deg);
    74. }
    75. .btn-two:hover {
    76. transform: rotateX(45deg);
    77. }
    78. /* 第三个按钮样式 */
    79. .btn-three {
    80. background-color: aqua;
    81. }
    82. .btn-three::after {
    83. background-color: rgb(26, 131, 131);
    84. transform: rotateY(-90deg);
    85. }
    86. .btn-three:hover {
    87. transform: rotateY(25deg);
    88. }
    89. /* 第四个按钮样式 */
    90. .btn-four {
    91. background-color: orange;
    92. }
    93. .btn-four::after {
    94. background-color: rgb(112, 78, 14);
    95. transform: rotateY(90deg);
    96. }
    97. .btn-four:hover {
    98. transform: rotateY(-25deg);
    99. }
    100. style>
    101. head>
    102. <body>
    103. <div class="container">
    104. <div class="btn-perspective">
    105. <button class="btn btn-3d btn-one">button>
    106. div>
    107. <div class="btn-perspective">
    108. <button class="btn btn-3d btn-two">button>
    109. div>
    110. <div class="btn-perspective">
    111. <button class="btn btn-3d btn-three">button>
    112. div>
    113. <div class="btn-perspective">
    114. <button class="btn btn-3d btn-four">button>
    115. div>
    116. div>
    117. body>
    118. html>

     三.总结

            这个按钮的亮点就是灵活使用了3D变换的相关知识,比如变换原点,设置景深,3D旋转等,会了其中一个便可以举一反三,期待大家的修改指正。 

  • 相关阅读:
    按关键字采集淘特商品列表API接口H5
    优先发展非化石能源
    推荐一个C#开发的窗口扩展菜单,支持系统所以窗口
    爬虫学习笔记-scrapy爬取电影天堂(双层网址嵌套)
    TypeScript知识点
    owasp top 10
    Mysql备份工具innobackupex简单操作及参数说明
    ElasticSearch7.3学习(二十一)----Filter与Query对比、使用explain关键字分析语法
    阿里蚂蚁淘宝等多次一面面试面经
    spring-boot 请求参数校验:注解 @Validated 的使用、手动校验、自定义校验
  • 原文地址:https://blog.csdn.net/weixin_73810008/article/details/136116554