Help us understand the problem. What is going on with this article?

CSSで五角柱をつくる。

More than 3 years have passed since last update.

CSSのみで五角形スライドアニメーションにインスピレーションを得たので違うやり方で作ってみた。

sample1.gif

この通り筒抜けである。

作り方1

<div class="pentagon1">
  <div class="lime">
    <div class="pink">
      <div class="aqua">
        <div class="gray">
          <div class="gold"></div>
        </div>
      </div>
    </div>
  </div>
</div>

面の数分の階層構造をつくる

.pentagon1{
  position: absolute;
  top: 50%;
  left: 50%;

  width: 100px;
  height: 100px;

  transform-style: preserve-3d;
  transform-origin: center center 50px;
}

.pentagon1 div{
  position: absolute;
  top: 100%;
  left: 50%;

  width: 100%;
  height: 100%;
  background-color: currentColor;

  transform-style: preserve-3d;
  transform-origin: center top;
  transform: translateX(-50%) rotateX(72deg);
}

/* colors */
.lime{ color: rgba(000,255,000,.65); }
.aqua{ color: rgba(000,255,255,.65); }
.pink{ color: rgba(255,192,203,.65); }
.gray{ color: rgba(200,200,200,.65); }
.gold{ color: rgba(255,215,000,.65); }

.view_anim{
  animation: view 3s linear infinite;
}

@keyframes view{
  from{
    transform: rotateY(50deg) rotateX(0deg);
  }
  to{
    transform: rotateY(50deg) rotateX(360deg);
  }
}

作り方2

<div class="pentagon2">
  <div class="pink"></div>
  <div class="lime"></div>
  <div class="gold"></div>
  <div class="lime"></div>
  <div class="aqua"></div>
</div>

.pentagon2{
  position: absolute;
  top: 50%;
  left: 50%;

  width: 100px;
  height: 100px;

  transform-style: preserve-3d;
  transform-origin: center center 50px;
}

.pentagon2 div{
  position: absolute;
  left: 50%;

  width: 100%;
  height: 100%;
  background-color: currentColor;
  transform-origin: center top;
}

.pentagon2 div:nth-of-type(1){ 
  transform: translate(-50%,0%); 
}

.pentagon2 div:nth-of-type(2){ 
  transform: translate(-50%,100%) rotateX(72deg); 
}

.pentagon2 div:nth-of-type(3){ 
  transform: 
    translate(-50%,100%) rotateX(72deg) 
    translateY(100%) rotateX(72deg);
}

.pentagon2 div:nth-of-type(4){
  transform: 
    translate(-50%,100%) rotateX(72deg)
    translateY(100%) rotateX(72deg) translateY(100%) 
    rotateX(72deg);
}

.pentagon2 div:nth-of-type(5){
  transform: 
    translate(-50%,100%) rotateX(72deg)
    translateY(100%) rotateX(72deg) translateY(100%) 
    rotateX(72deg) translateY(100%) rotateX(72deg);
}

/* colors */
.lime{ color: rgba(000,255,000,.65); }
.aqua{ color: rgba(000,255,255,.65); }
.pink{ color: rgba(255,192,203,.65); }
.gray{ color: rgba(200,200,200,.65); }
.gold{ color: rgba(255,215,000,.65); }

.view_anim{
  animation: view 3s linear infinite;
}

@keyframes view{
  from{
    transform: rotateY(50deg) rotateX(0deg);
  }
  to{
    transform: rotateY(50deg) rotateX(360deg);
  }
}

作り方1,作り方2も 立体の面同士の角度を求めれば作れます
五角柱の場合 角度は360 / 5 = 72度

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away