LoginSignup
29
29

More than 5 years have passed since last update.

CSSで紙がめくれたような影をつける【四角・丸】

Last updated at Posted at 2015-10-06

四角い紙に影をつけるものはたくさんあったけど、
丸いのがなかったからつくってみた。

四角

スクリーンショット 2015-10-06 12.26.54.png

<div class="square shadow"></div>
.shadow {
    position: relative;
}
.shadow:after {
    position: absolute;
    right: 2px;
    bottom: 5px;
    content: '';
    width: 45%;
    height: 10px;
    background: #aaa;
    box-shadow: 0 6px 12px #aaa;
    transform: rotate(3deg);
    z-index: -1;
}

スクリーンショット 2015-10-06 12.27.02.png

<div class="circle shadow circleShadow"></div>
.circleShadow:after {
    right: 1px;
    bottom: 8px;
    width: 80%;
    height: 80%;
    border-radius: 50%
}

おまけ

ホバーしたら影がつく

.shadow {
    position: relative;
    transition: 0.5s;
}
.shadow:after {
    opacity: 0;
    position: absolute;
    right: 2px;
    bottom: 5px;
    content: '';
    width: 45%;
    height: 10px;
    background: #aaa;
    box-shadow: 0 6px 12px #aaa;
    transform: rotate(3deg);
    z-index: -1;
    transition: 0.5s;
}
.shadow:hover:after {
    opacity: 1;
}

※transitionを使う場合、bodyに背景を設定しないとtransitionの時間の間背景色が変わってしまうみたいです。

29
29
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
29
29