3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CSSでツリーを作る。

Last updated at Posted at 2015-12-24

sample001.gif

ツリーにマウスカーソルを乗せるとメッセージが出てくる。

HTML


<div class="tree">
  <div class="leaves green"></div>
  <div class="trunk brown"></div>
  <p class="message">Merry Christmas</p>
</div>

CSS


.tree{
  position: relative;
  width: 100px;
  height: 100px;
}

.tree .leaves{
  position: absolute;
  bottom: 15%;
  left: 50%;
  border: 40px solid transparent;
  border-bottom: 30px solid currentColor;
  transform: translate(-50%,-50%);
  box-sizing: border-box;
  z-index: 2;
}

/* 共通部分 */
.tree .leaves:before,
.tree .leaves:after{
  position: absolute;
  content: "";
  border: inherit;
  border-bottom: inherit;
  box-sizing: inherit;
}

.tree .leaves:before{
  transform: translate(-50%,-35%) scale(1.15,1.13);
}

.tree .leaves:after{
  transform: translate(-50%,-18%) scale(1.3,1.25);
}

.tree .trunk{
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 20%;
  height: 20%;
  border-radius: 10% / 20%;
  background-color: currentColor;
  transform: translateX(-50%);
  z-index: 1;
}

.tree .message{
  position: absolute;
  bottom: 0;
  left: 50%;
  display: inline-block;
  margin: 0;
  font-size: 2rem;
  letter-spacing: -2rem;
  color: transparent;
  white-space: nowrap;
  transition: 1s;
}

.tree:hover > .message{
  left: 100%;
  letter-spacing: 0;
  color: red;
}

/* 色 */
.green{
  color: green;
}

.brown{
  color: #9D3718;
}

leaves(葉)の部分はborderで三角形を作って表現しています。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?