LoginSignup
6
8

More than 5 years have passed since last update.

background-imageやborder-colorにcurrentColorを使う

Posted at

変数みたいなことがでける

プレーンCSSで唯一使える変数(みたいなやつ)currentColorを使うと、background-imagebackground-colorborder-colorcolorで設定できます。オメガ嬉しいときもあるけれど、日常的にはあってもなくても感もあります。

html
<div class="foo red"></div>
<div class="foo green"></div>
<div class="foo blue"></div>
css
.foo{
    width:100px;
    height:100px;
    margin:10px;
    background-image:linear-gradient(to bottom,
        currentColor 20%,
        transparent 20%,
        transparent 40%,
        currentColor 40%,
        currentColor 60%,
        transparent 60%,
        transparent 80%,
        currentColor 80%);
    border:1px solid currentColor;
}
.red{
    color:red;
}
.green{
    color:green;
}
.blue{
    color:blue;
}

動作サンプル

6
8
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
6
8