我试图创建这个美丽的动画使用html和css动画关键帧,但我卡住了.我试过改变旋转和变换,但我不能得到它变成像下面的图像.你可以从下面的图片中看到,盒子向内折叠以隐藏文本"Hi",然后它们向外展开,再次显示文本.盒子的 colored颜色 不是问题,我的动画有问题.

这就是我到目前为止所做的.

/* styles.css */
.container {
  display: flex;
  justify-content: center;
  align-items: center; 
  height: 400px; 
}

.group {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 200px;
  margin: 0 15px; 
}

.topleft {
  width: 100px; 
  height: 75px; 
  border-radius: 10px;
  margin: 0 auto;
  transform-origin: bottom left;
}

.topright {
  width: 100px; 
  height: 75px; 
  border-radius: 10px;
  margin: 0 auto;
  transform-origin: bottom left;
}

.bottomleft {
  width: 100px; 
  height: 75px; 
  border-radius: 10px;
  margin: 0 auto;
  transform-origin: bottom right;
}

.bottomright {
  width: 100px; 
  height: 75px; 
  border-radius: 10px;
  margin: 0 auto;
  transform-origin: bottom left;
}

.topleft {
  background-color: steelblue;
  animation: rotateTopLeft 2s linear infinite; 
}

.topright {
  background-color: steelblue;
  animation: rotateTopRight 2s linear infinite; 
}

.bottomleft {
  background-color: steelblue;
  animation: rotateTopLeft 2s linear infinite; 
}

.bottomright {
  background-color: steelblue;
  animation: rotateTopRight 2s linear infinite; 
}

@keyframes rotateTopLeft {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(-90deg);
  }
}

@keyframes rotateTopRight {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(-90deg);
  }
}

@keyframes rotateBottomLeft {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(90deg);
  }
}

@keyframes rotateBottomRight {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(-90deg);
  }
}

.bottomleft {
  background-color: yellow;
}

.topright {
  background-color: rosybrown;
}

.topright {
  background-color: diegray;
}

.space {
  width: 100px; 
  height: 75px; 
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
}
  <div class="container">
    <div class="group left">
      <div class="box topleft steelblue"></div>
      <div class="box bottomleft yellow"></div>
    </div>
    <div class="space">Hi</div>
    <div class="group right">
      <div class="box topright diegray"></div>
      <div class="box bottomright rosybrown"></div>
    </div>
  </div>

Box unfold animation using html and css

推荐答案

这是我的 idea .悬停以查看动画:

.box {
  width: 200px;
  aspect-ratio:1;
  display: grid;
  place-content: center;
  margin: auto;
  font-size: 40px;
  position: relative;
}
.box:before,
.box:after,
.box span:before,
.box span:after {
  content:"";
  position: absolute;
  width: 50%;
  height: 50%;
  transition: 1s;
}
.box:before {
  inset: 0 auto auto 0;
  transform-origin: 0 0;
  background: pink;
  rotate: var(--r,0deg);
}
.box:after {
  inset: 0 0 auto auto;
  transform-origin: 100% 0;
  background: lightblue;
  rotate: calc(-1*var(--r,0deg));
}
.box span:before {
  inset: auto auto 0 0;
  transform-origin: 0 100%;
  background: red;
  rotate: calc(-1*var(--r,0deg));
}
.box span:after {
  inset: auto 0 0 auto;
  transform-origin: 100% 100%;
  background: blue;
  rotate: var(--r,0deg);
}

.box:hover {
  --r: 90deg;
}
<div class="box">
  hi
  <span></span>
</div>

Html相关问答推荐

css网格区域的布局不展开,也不显示滚动条

未显示新组件的视图

VBA从公共Google Drive地址下载文档-.Click事件(?)

具有可展开行的棱角material 表(垫子表),折叠时行之间仍有间隙

覆盖垫子中的边框底部 Select

IFRAME中的Chrome图像未调整大小

如何在小屏幕中制作水平滚动div

悬停表格单元格文本时,使元素的字体大小更大,同时保持表格单元格的高度不变

网格中的图像zoom 不正确

在 HTML 视频上环绕文本叠加

如何在CSS伪类函数中使用复合 Select 器:host-context()

当作为常规图片输入时,Cloudfront分布式图像可显示,但作为背景图像不显示

CSS "overflow"不能显示整个单词

Bootstrap 轮播内容在箭头之间不显示

拨动switch 在重新加载时未重置

为什么我的 div 元素没有形成一个圆形时钟?

高度大于页面高度和页面大于覆盖的 CSS 覆盖

标签背景 colored颜色 的 html 和 css 技巧说明

如何根据行中的其中一列将行居中?

Mediawiki css/html 信息框创建空白行