Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What is going on with this article?
@junya

CSSで四季を表現してみた。

More than 1 year has passed since last update.

sample.png

実際の動作を確認したい人向け
https://junya0215.github.io/cacao_ame/design_art/season/

<div class="circle"></div>
<script>
var root  = document.querySelector('body > div');
var season = ['spring','summer','autumn','winter'];

for(var i = 0; i < 4; i++){
  var tree = document.createElement('div');
  tree.className = 'tree '+ season[i];
  root.appendChild(tree);

  fractal(4,tree);
}

function fractal(hr_cnt,node) {
  if(hr_cnt <= 0) return;

  var e1 = document.createElement('div');
  var e2 = document.createElement('div');

  node.appendChild(e1);
  node.appendChild(e2);

  fractal(hr_cnt - 1,e1);
  fractal(hr_cnt - 1,e2);
}
</script>

CSS


body{
  background-color: black;
}

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

  width: 300px;
  height: 300px;
  border: 150px solid;
  /* 上 右 下 左 */
  border-color: #FFBFD3 #0050BC #F1CE6A #FFFAFA;
  border-radius: 100%;
  box-sizing: border-box;

  transform: translate(-50%,-50%);
}

.tree{
  position: fixed;
  bottom: 50%;
  left: 50%;

  width: 6px;
  height: 75px;
  background-image: linear-gradient(to top,transparent 25%,#8A5533);

  transform-origin: center bottom;
}

.tree.spring{ transform: translate(-50%,0) rotate(0deg);  }
.tree.summer{ transform: translate(-50%,0) rotate(90deg); }
.tree.autumn{ transform: translate(-50%,0) rotate(180deg);}
.tree.winter{ transform: translate(-50%,0) rotate(270deg);}

/* 枝 */
.tree div{
  position: absolute;
  bottom: 90%;
  left: 50%;

  width: 100%;
  height: 65%;
  border-radius: 100% 100% 0 0;

  background-color: #8A5533;
}

.tree div:nth-child(odd){
  transform-origin: right bottom;
  transform: translateX(-50%) rotate(-20deg) skewY(-10deg);
}

.tree div:nth-child(even){
  transform-origin: left bottom;
  transform: translateX(-50%) rotate(20deg) skewY(5deg);
}

.tree div:empty{
  box-shadow: 0 20px 0 0 currentColor inset; 
}

.tree div:empty:after{
  content: "";

  position: absolute;
  bottom: 95%;
  left: 45%;

  width: 0;
  height: 0;
  border: 10px solid transparent;

  box-shadow: none;
  box-sizing: border-box;

  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  backface-visibility: hidden;

  transform: translateX(-50%);
  z-index: 1;
}

/* 季節 */
.spring div:nth-child(odd):empty { color: #FFBFD3; }
.spring div:nth-child(even):empty{ color: #FBF0F2; }
.summer div:nth-child(odd):empty { color: #1F5F22; }
.summer div:nth-child(even):empty{ color: #6FB545; }
.autumn div:nth-child(odd):empty { color: #E90003; }
.autumn div:nth-child(even):empty{ color: #F49003; }
.winter div:nth-child(odd):empty { color: snow; }
.winter div:nth-child(even):empty{ color: snow; }

.spring div:empty:after{ 
  border-radius: 100%;
}

.summer div:empty:after{ 
  border-radius: 100% 0 100% 0;
}

.autumn div:empty:after{
  border-radius: 100% 0 100% 100%;
  transform: translateX(-50%) rotate(-45deg) skewX(15deg);
}

.winter div:empty:after{
  border: none;
}

/* アニメーション */
.tree div{
  animation: grow 3s linear both;
}

.tree div:empty:after{
  animation: flowering 3s 3s linear both;
}

.winter:hover div:empty:after{
  content: "*  *";
  animation: snow_fall 3s linear infinite;
}

@keyframes grow{
  from{
    height: 0;
  }
  to{
    height: 95%;
  }
}

@keyframes flowering{
  to{
    border-color: currentColor;
    box-shadow: 0 15px 50px 2px currentColor;
  }
}

@keyframes snow_fall{
  to{
    bottom: -50%;
    color: transparent;
    transform: rotate(90deg);
  }
}

木の構造は下記を参照
CSSで桜をつくる

7
Help us understand the problem. What is going on with this article?
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
junya

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
7
Help us understand the problem. What is going on with this article?