27
27

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でimgに影つけてボタンっぽくする

Posted at

##サンプル

https://gyazo.com/1eb8fe26f5d2be5535e1f56977f42d0d
http://codepen.io/maruware/pen/YGPKVN

手順

filter: drop-shadow

filter: drop-shadowは透過画像の非透過部分に影をつけられる。

.btn.github{
    -webkit-filter: drop-shadow(0px 7px 0 #ccc);
    filter: drop-shadow(0px 7px 0 #ccc);
}

.btn.qiita{
    -webkit-filter: drop-shadow(0px 7px 0 #459109);
    filter: drop-shadow(0px 7px 0 #459109);
}

のように影の色をそれっぽくして設定。
Adobe Colorで元の色入れてイジると楽。

transition

.btn {
    transition-property: all;
    transition-duration: 0.1s;
    transition-timing-function: ease-in-out;

    position: relative;
    top: 0px;
}

.btn:active {
  top: 7px;
}

.btn.github:active {
  -webkit-filter: drop-shadow(0 0 0 #ccc);
  filter: drop-shadow(0 0 0 #ccc);
}

.btn.qiita:active {
  -webkit-filter: drop-shadow(0 0 0 #459109);
  filter: drop-shadow(0 0 0 #459109);
}

などとしてtransitionでアニメーションする。
positionを影のサイズ分下げて押し込んだようにする。

27
27
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?