当前位置:   article > 正文

纯CSS简单案例合集(折扇效果,资料卡,定格轮播,菜单三角形)_纯css实现扇形菜单

纯css实现扇形菜单

目录

①折扇效果(2d动画)

 ②资料卡

 ③定格轮播(鼠标移上去会暂停)


度数,速度,颜色之类的可以自己再调整

效果图如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. *{margin: 0;padding: 0;}
  10. ul{list-style-type:none;}
  11. ul{
  12. margin: 10px auto;
  13. width: 600px;
  14. height: 400px;
  15. border: 4px solid gray;
  16. position: relative;
  17. }
  18. li{
  19. width: 50px;
  20. height: 200px;
  21. position: absolute;
  22. left: 50%;
  23. margin-left: -30px;
  24. bottom: 30px;
  25. text-align: center;
  26. transform-origin: bottom center;
  27. transition: all 3s linear;
  28. border-radius: 5px;
  29. box-shadow: 2px 2px 2px black;
  30. }
  31. ul li:nth-child(1),ul li:nth-child(13){
  32. background-color: purple;
  33. }
  34. ul li:nth-child(2),ul li:nth-child(12){
  35. background-color:blueviolet;
  36. }
  37. ul li:nth-child(3),ul li:nth-child(11){
  38. background-color:rgb(226, 43, 226);
  39. }
  40. ul li:nth-child(4),ul li:nth-child(10){
  41. background-color:pink;
  42. }
  43. ul li:nth-child(5),ul li:nth-child(9){
  44. background-color:rgb(233, 108, 129);
  45. }
  46. ul li:nth-child(6),ul li:nth-child(8){
  47. background-color:rgb(228, 66, 93);
  48. }
  49. ul li:nth-child(7){
  50. background-color:rgb(167, 49, 69);
  51. }
  52. ul:hover li:nth-child(13){
  53. transform: rotate(-85deg);
  54. }
  55. ul:hover li:nth-child(12){
  56. transform: rotate(-75deg);
  57. }
  58. ul:hover li:nth-child(11){
  59. transform: rotate(-60deg);
  60. }
  61. ul:hover li:nth-child(10){
  62. transform: rotate(-45deg);
  63. }
  64. ul:hover li:nth-child(9){
  65. transform: rotate(-30deg);
  66. }
  67. ul:hover li:nth-child(8){
  68. transform: rotate(-15deg);
  69. }
  70. ul:hover li:nth-child(6){
  71. transform: rotate(15deg);
  72. }
  73. ul:hover li:nth-child(5){
  74. transform: rotate(30deg);
  75. }
  76. ul:hover li:nth-child(4){
  77. transform: rotate(45deg);
  78. }
  79. ul:hover li:nth-child(3){
  80. transform: rotate(60deg);
  81. }
  82. ul:hover li:nth-child(2){
  83. transform: rotate(75deg);
  84. }
  85. ul:hover li:nth-child(1){
  86. transform: rotate(85deg);
  87. }
  88. </style>
  89. </head>
  90. <body>
  91. <ul>
  92. <li></li>
  93. <li></li>
  94. <li></li>
  95. <li></li>
  96. <li></li>
  97. <li></li>
  98. <li></li>
  99. <li></li>
  100. <li></li>
  101. <li></li>
  102. <li></li>
  103. <li></li>
  104. <li></li>
  105. </ul>
  106. </body>
  107. </html>

 ②资料卡

  

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. *{
  10. margin: 0;
  11. padding: 0;
  12. }
  13. img{
  14. display: block;
  15. }
  16. .box{
  17. width: 350px;
  18. overflow: hidden;
  19. margin: 0 auto;
  20. position: relative;
  21. }
  22. .box img{
  23. width: 100%;
  24. transition: all 1s
  25. }
  26. .box:hover img{
  27. transform: translateX(50px);
  28. opacity: 0.5;
  29. }
  30. .box h2{
  31. position:absolute;
  32. left: 50px;
  33. top: 10px;
  34. color: wheat;
  35. transition: all 1s 0.3s;
  36. }
  37. .box:hover h2{
  38. transform: translateX(100px);
  39. }
  40. .box p{
  41. position: absolute;
  42. left:50px;
  43. width: 100px;
  44. color: white;
  45. background: rgb(108, 108, 190);
  46. }
  47. .box .p1{
  48. top: 60px;
  49. transform: translateY(300px);
  50. transition: all 1s;
  51. }
  52. .box:hover .p1{
  53. transform: translateY(0px);
  54. }
  55. .box .p2{
  56. top: 110px;
  57. transform: translateY(400px);
  58. transition: all 1s;
  59. }
  60. .box:hover .p2{
  61. transform: translateY(0px);
  62. }
  63. .box .p3{
  64. top:160px;
  65. transform: translateY(400px);
  66. transition: all 1s;
  67. }
  68. .box:hover .p3{
  69. transform: translateY(0px);
  70. }
  71. </style>
  72. </head>
  73. <body>
  74. <div class="box">
  75. <img src="../tu/7.jpg" alt="">
  76. <h2>aespa</h2>
  77. <p class="p1">black manba</p>
  78. <p class="p2">savage</p>
  79. <p class="p3">forever</p>
  80. </div>
  81. </body>
  82. </html>

 ③定格轮播(鼠标移上去会暂停)

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <!-- 原理 一个大容器里面一个很长的盒子,盒子里装了浮动的图片,不断改变长盒子的位置实现轮播,图片可以再根据需要增删-->
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. }
  14. .container {
  15. /* 固定高宽 */
  16. width: 640px;
  17. height: 300px;
  18. margin: 0 auto;
  19. overflow: hidden;
  20. }
  21. .swiper img {
  22. width: 640px;
  23. height: 300px;
  24. }
  25. .slider {
  26. float: left;
  27. }
  28. .swiper {
  29. width: 5000px;
  30. /* 只要大于图片加起来的宽度就行 */
  31. animation: swipers 8s linear infinite;
  32. }
  33. @keyframes swipers {
  34. /* 10,43,76实现图片定格*/
  35. 0% {
  36. transform: translateX(0);
  37. }
  38. 10% {
  39. transform: translateX(-640px);
  40. }
  41. 33% {
  42. transform: translateX(-640px);
  43. }
  44. 43% {
  45. transform: translateX(-1280px);
  46. }
  47. 66% {
  48. transform: translateX(-1280px);
  49. }
  50. 76% {
  51. transform: translateX(-1920px);
  52. }
  53. 100% {
  54. transform: translateX(-1920px);
  55. }
  56. }
  57. .swiper:hover{
  58. animation-play-state: paused;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div class="container">
  64. <div class="swiper">
  65. <div class="slider">
  66. <img src="../tu/5.jpg" alt="">
  67. </div>
  68. <div class="slider">
  69. <img src="../tu/6.jpg" alt="">
  70. </div>
  71. <div class="slider">
  72. <img src="../tu/7.jpg" alt="">
  73. </div>
  74. <!-- 实现无缝轮播,第一张和最后一张图片一样 -->
  75. <div class="slider">
  76. <img src="../tu/5.jpg" alt="">
  77. </div>
  78. </div>
  79. </div>
  80. </body>
  81. </html>

④三角形菜单栏

实现原理:先定义一个盒子,设置宽高,将border设置成不同的宽度和颜色

​​​​​​​

 

会出现以上效果 ,可以想象,当每个色彩栏中间的宽度不断缩小,就变成了三角形,当div的高宽变成0时,就变成了如图所示,将其他颜色改变为背景色是不可取的,如果背景色改变一眼就能看出,将其他改为transparent即可

效果图

 

  1. <head>
  2. <meta charset="UTF-8">
  3. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <title>Document</title>
  6. <style>
  7. .box {
  8. width: 100px;
  9. height: 50px;
  10. line-height: 50px;
  11. text-align: center;
  12. background: lightblue;
  13. color: white;
  14. }
  15. span {
  16. width: 0;
  17. height: 0;
  18. display: inline-block;
  19. border: 5px solid transparent; /* 变三角形 */
  20. border-top: 5px solid white;
  21. position: relative; /*给三角形一个固定位置变化*/
  22. top: 2.5px;
  23. transition: 0.3s; /* 0.3s变化*/
  24. }
  25. .box:hover span {
  26. border: 5px solid transparent;/* 变三角形 */
  27. border-bottom: 5px solid white;
  28. position: relative;/*给三角形一个固定位置变化*/
  29. top: -2px;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="box"> 导航
  35. <span></span>
  36. </div>
  37. </body>
  38. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/853382
推荐阅读
相关标签
  

闽ICP备14008679号