纯css卡片层叠切换效果

代码语言:html

所属分类:幻灯片

代码描述:纯css卡片层叠切换效果

代码标签: 层叠 切换 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<link href="https://fonts.googleapis.com/css2?family=Cabin:wght@400;700&display=swap" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="http://repo.bfw.wiki/bfwrepo/css/all.min.css">
<style>
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  display: grid;
  align-items: center;
  justify-items: center;
  height: 100%;
  color: #f4f7f7;
  background-color: #586875;
  font: 1rem/1 'Cabin', sans-serif;
  overflow-x: hidden;
}

/* hide radio buttons, but still expose them to screen readers */
input {
  position: absolute;
  width: 1px;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

.selector {
  display: grid;
  grid-template-areas:
    'happy lovers'
    'pick  pick';
}

/* the cards and toggle buttons are actually fat labels that can be clicked to set radio buttons */
label {
  display: block;
  cursor: pointer;
}

.happy-card, .lovers-card {
  position: relative; /* for iOS */
  width: 250px;
  padding: 20px;
  color: #586875;
  background-color: #f4f7f7;
  box-shadow: 0 10px 20px #0006;
  animation-duration: 0.5s;
  animation-timing-function: ease-in-out; /* important to use a symmetrical timing function (linear also works) */
  animation-fill-mode: forwards;
}

.happy-card {
  grid-area: happy;
  margin-right: -10px; /* nudge closer to lover's card */
  
  /* these values are used to animate via translateX */
  --swing: -25px;
  --overlap: 25px;
}

.lovers-card {
  grid-area: lovers;
  margin-left: -10px; /* nudge closer to happy card */

  /* these values are used to animate via translateX */
  --swing: 25px;
  --overlap: -25px;
}

/* when a radio button is set, swing the corresponding card fowards */
#happy-radio:checked ~ .selector .happy-card,
#lovers-radio:checked ~ .selector .lovers-card {
  animation-name: swing-forwards;
}

@keyframes swing-forwards {
  0% {
    z-index: 1; /* start behind other card */
    transform: scale(0.9);
  }
  50% {
    transform: translateX(var(--swing));
  }
  100% {
    z-index: 2; /* end in front of other card */
    transform: translateX(var(--overlap)) scale(1.1);
  }
}

/* when a radio button is set, swing the opposite card backwards */
#happy-radio:checked ~ .selector .lovers-card,
#lovers-radio:checked ~ .selector .happy-card {
  animation-name: swing-backwards;
}

@keyframes swing-backwards {
  0% {
    z-index: 2;  /* start in front of other card */
    transform: translateX(var(--overlap)) scale(1.1);
  }
  50% {
    transform: translateX(var(--swing));
  }
 .........完整代码请登录后点击上方下载按钮下载查看

网友评论0