html - 如何仅使用 CSS 创建三 Angular 形动画

标签 html css css-animations

我想像这样构建动画,但只使用 css:

enter image description here

我构建了一个三 Angular 形,但无法构建会移动的移动三 Angular 形背景。请参阅图片中的示例。

我的代码:

HTML:

 <div class="container">
        <div class="triangle up">
        </div>
        <div class="triangle down-right">

        </div>
        <div class=" down-right1">
        </div>

        <div class="triangle down-left">
        </div>
    </div>

CSS:

.container {
    position: relative;
    left: 45%;
    width: 300px;
    height: 250px;
}

.triangle {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-bottom: 100px solid rgb(165,60,255);
    background: linear-gradient(90deg, rgba(165,60,255,1) 0%, rgba(98,0,255,1) 100%);
    z-index: 999999;
}

.up {
    top: 0;
    left: auto;
}


.down-right {
    top: 100px;
    left: 16.5%;
}

.down-right1 {
    top: 105px;
    left: 24%;
    position: absolute;
    width: 0;
    height: 0;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-bottom: 100px solid #c85e5e;
}


.down-left {
    top: 100px;
    left: -16.5%;
}

我希望这个动画在页面加载时开始。

最佳答案

一个使用倾斜变换和盒子阴影的想法。

.box {
  position: fixed;
  margin: auto;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 75px;
  height: 64.5px;
  transition: 0.5s all 0.5s;
  transform-origin: 50% 63%;
}

.box::before,
.box::after,
.box i:before,
.box i:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 8px;
  transform-origin: bottom;
  transition: 0.5s all;
}

.box::before {
  background: #5840bc;
  box-shadow: 0px -20px #886df8, 0px -40px #c2b3f8;
  transform: skewX(-30deg);
  border-bottom-right-radius: 0;
}

.box::after {
  background: #5844d9;
  box-shadow: -20px 0 #7d69ca, -40px 0 #c7bee9;
  transform: skewX(30deg);
  border-top-right-radius: 0;
}

.box i:before {
  background: #714ffe;
  box-shadow: 0px -20px #7c6ade, 0px -40px #c7bee9;
  transform: translateY(50%) rotate(120deg) skewX(-30deg);
  transform-origin: center;
  border-bottom-right-radius: 0;
}

.box i:after {
  background: #fff;
  z-index: 1;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  border-radius: 0;
}

html:hover .box {
  transform: rotate(60deg);
}

html:hover .box::before,
html:hover .box::after,
html:hover .box i:before,
html:hover .box i:after {
  box-shadow: 0px 0 transparent, 0px 0 transparent;
}
<div class="box"><i></i></div>

关于html - 如何仅使用 CSS 创建三 Angular 形动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65644084/

相关文章:

html - 两条边倾斜度不同的 Div

css - 如何在同一顶层的内容 div 中左右对齐 div?

html - 简单的 CSS 关键帧动画不起作用

css - Webkit 动画和转换

javascript - 如何将图像 div 放在文本 div 旁边?

html - 如何在CSS中用颜色覆盖图像?

css - 在一行中居中列 BOOTSTRAP

css - webkit 动画适用于 chrome 但不适用于 firefox

html - 嵌套的 Flexbox 拉伸(stretch)图像

css - 像 Ionic 2 中的 Modal 一样发出警报