css text-fill-color与text-stroke讲解

顾名思义“text-fill-color”就是文字填充颜色而“text-stroke”就是文字描边。还别说,两个属性能够制做出各类炫酷的文字效果,不过IE系列都不支持,不过好在webkit都支持良好。web

text-fill-color:color;

<style>
    h1{
        -webkit-text-fill-color:red;
    }
</style>
<h1>博客园</h1>

话说倒有点像color了,这种状况下却是和color真的是同样的。动画

得注意一下:若是同时设置了text-fill-colorcolor那么color不会起做用。url

h1{
    -webkit-text-fill-color:red;
    color:green;
}
text-stroke:width color;

<style>
    h1{
        -webkit-text-stroke:1px red;
    }
</style>
<h1>博客园</h1>

好像这两个单独使用没有啥亮点,但若是结合起来使用那就不同了。spa

text-stroke + text-fill-color制做文字镂空效果

<style>
    body{
        background-color:#000;
    }
    h1{
        font-size:60px;
        -webkit-text-fill-color:transparent;
        -webkit-text-stroke:1px #fff;
    }
</style>
<h1>博客园</h1>

原来就是设置边框为白色而后然文字颜色透明,背景颜色黑色,也就是黑白对比,天然文字就只能看见边框了。code

若是再结合一下“background-clip”那就更强大了。

background-clip:text结合text-fill-color制做文字渐变效果

h1{
    font-size:60px;
    background: linear-gradient(to bottom,#FCF,#000);
    -webkit-background-clip:text;
    -webkit-text-fill-color:transparent;
}

注意:background-clip必须放在background后面否则不起做用,之因此要用background是由于text-fill-color不能使用linear因此只好借助background了。blog

background-clip:text会将背景做为文字区域裁剪。

<style>
    h1{
        font-size:60px;
        background: url(bg.jpg) repeat;
        -webkit-background-clip:text;
        -webkit-text-fill-color:transparent;
    }
</style>
<h1>博客园</h1>
利用animation制做文字遮罩动画效果

<style>
    h1{
        font-size:60px;
        background: url(bg.jpg) repeat;
        -webkit-background-clip:text;
        -webkit-text-fill-color:transparent;
        animation:fn 5s alternate infinite;
    }
    @keyframes fn{
            0%{
                background-position:0px 0px;
            }
            20%{
                background-position:30% 0px;
            }
            50%{
                background-position:50% 0px;
            }
            70%{
                background-position:70% 0px;
            }
            100%{
                background-position:100% 0px;
            }
    }
</style>
<h1>博客园</h1>

待续...ip

相关文章
相关标签/搜索