爬行的蜗牛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: golang Linux PHP
查看: 106|回复: 0

HTML+CSS实现“卡片轮播”

[复制链接]

134

主题

41

回帖

1031

积分

管理员

积分
1031
发表于 2024-11-23 18:59:37 | 显示全部楼层 |阅读模式
111.gif
这是对传统旋转木马的创新设计。卡片重叠排列,节省空间。当你将鼠标悬停在某张卡片上时,它会显现出来。虽然这个例子在活跃卡片上显示圆形动画,但你也可以调整它来展示文本或图像。

HTML

  1. <head>
  2.   <link href="https://fonts.googleapis.com/css?family=Open+Sans:300i,400" rel="stylesheet">
  3. </head>
  4. <body>
  5. <div class="container">
  6.   <div class="card">
  7.     <h3 class="title">Card 1</h3>
  8.     <div class="bar">
  9.       <div class="emptybar"></div>
  10.       <div class="filledbar"></div>
  11.     </div>
  12.     <div class="circle">
  13.       <svg version="1.1" xmlns="http://www.w3.org/2000/svg">
  14.       <circle class="stroke" cx="60" cy="60" r="50"/>
  15.     </svg>
  16.     </div>
  17.   </div>
  18.   <div class="card">
  19.     <h3 class="title">Card 2</h3>
  20.     <div class="bar">
  21.       <div class="emptybar"></div>
  22.       <div class="filledbar"></div>
  23.     </div>
  24.     <div class="circle">
  25.       <svg version="1.1" xmlns="http://www.w3.org/2000/svg">
  26.       <circle class="stroke" cx="60" cy="60" r="50"/>
  27.     </svg>
  28.     </div>
  29.   </div>
  30.   <div class="card">
  31.     <h3 class="title">Card 3</h3>
  32.     <div class="bar">
  33.       <div class="emptybar"></div>
  34.       <div class="filledbar"></div>
  35.     </div>
  36.     <div class="circle">
  37.       <svg version="1.1" xmlns="http://www.w3.org/2000/svg">
  38.       <circle class="stroke" cx="60" cy="60" r="50"/>
  39.     </svg>
  40.     </div>
  41.   </div>
  42.   <div class="card">
  43.     <h3 class="title">Card 4</h3>
  44.     <div class="bar">
  45.       <div class="emptybar"></div>
  46.       <div class="filledbar"></div>
  47.     </div>
  48.     <div class="circle">
  49.       <svg version="1.1" xmlns="http://www.w3.org/2000/svg">
  50.       <circle class="stroke" cx="60" cy="60" r="50"/>
  51.     </svg>
  52.     </div>
  53.   </div>
  54. </div>
  55. </body>
复制代码
CSS
  1. body {
  2.   background-color: #100e17;
  3.   font-family: 'Open Sans', sans-serif;
  4. }

  5. .container {
  6.   position: absolute;
  7.   height: 300px;
  8.   width: 600px;
  9.   top: 60px;
  10.   left: calc(50% - 300px);
  11.   display: flex;
  12. }

  13. .card {
  14.   display: flex;
  15.   height: 280px;
  16.   width: 200px;
  17.   background-color: #17141d;
  18.   border-radius: 10px;
  19.   box-shadow: -1rem 0 3rem #000;
  20. /*   margin-left: -50px; */
  21.   transition: 0.4s ease-out;
  22.   position: relative;
  23.   left: 0px;
  24. }

  25. .card:not(:first-child) {
  26.     margin-left: -50px;
  27. }

  28. .card:hover {
  29.   transform: translateY(-20px);
  30.   transition: 0.4s ease-out;
  31. }

  32. .card:hover ~ .card {
  33.   position: relative;
  34.   left: 50px;
  35.   transition: 0.4s ease-out;
  36. }

  37. .title {
  38.   color: white;
  39.   font-weight: 300;
  40.   position: absolute;
  41.   left: 20px;
  42.   top: 15px;
  43. }

  44. .bar {
  45.   position: absolute;
  46.   top: 100px;
  47.   left: 20px;
  48.   height: 5px;
  49.   width: 150px;
  50. }

  51. .emptybar {
  52.   background-color: #2e3033;
  53.   width: 100%;
  54.   height: 100%;
  55. }

  56. .filledbar {
  57.   position: absolute;
  58.   top: 0px;
  59.   z-index: 3;
  60.   width: 0px;
  61.   height: 100%;
  62.   background: rgb(0,154,217);
  63.   background: linear-gradient(90deg, rgba(0,154,217,1) 0%, rgba(217,147,0,1) 65%, rgba(255,186,0,1) 100%);
  64.   transition: 0.6s ease-out;
  65. }

  66. .card:hover .filledbar {
  67.   width: 120px;
  68.   transition: 0.4s ease-out;
  69. }

  70. .circle {
  71.   position: absolute;
  72.   top: 150px;
  73.   left: calc(50% - 60px);
  74. }

  75. .stroke {
  76.   stroke: white;
  77.   stroke-dasharray: 360;
  78.   stroke-dashoffset: 360;
  79.   transition: 0.6s ease-out;
  80. }

  81. svg {
  82.   fill: #17141d;
  83.   stroke-width: 2px;
  84. }

  85. .card:hover .stroke {
  86.   stroke-dashoffset: 100;
  87.   transition: 0.6s ease-out;
  88. }
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表