【Css】你会写花里胡哨的文字吗?

2019-01-10  本文已影响0人  ___Jing___

设计师有没有给你过这样霸气的设计?


霸气外漏

怎么办?怎么写?一个个要图片?NoNoNo~会被鄙视的!

来,让咱们看一个关于背景的属性~background-clip

<style>
/* css */
    #box{
        width:100px;
        height: 100px;
        border:20px dashed #ad160b;
        padding: 30px;
        background:url(https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547122821339&di=e28b725cddbecf688cb827c96f726ab0&imgtype=0&src=http%3A%2F%2Fpic.51yuansu.com%2Fpic%2Fcover%2F00%2F24%2F02%2F57e3203eb1eb3_610.jpg);
        background-position: center;
        background-clip:border-box;
    }
</style>
<!-- DOM  -->
<div id="box"></div>

如下图,可以理解为将border区域也用背景图片进行填充


border-box

2.padding-box

<style>
/* css */
    #box{
        width:100px;
        height: 100px;
        border:20px dashed #ad160b;
        padding: 30px;
        background:url(https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547122821339&di=e28b725cddbecf688cb827c96f726ab0&imgtype=0&src=http%3A%2F%2Fpic.51yuansu.com%2Fpic%2Fcover%2F00%2F24%2F02%2F57e3203eb1eb3_610.jpg);
        background-position: center;
        background-clip:padding-box;
    }
</style>
<!-- DOM  -->
<div id="box"></div>

将整个padding+content区域都用背景进行填充,这个和content-box进行对比会比较清晰。


padding-box
  1. content-box
<style>
/* css */
    #box{
        width:100px;
        height: 100px;
        border:20px dashed #ad160b;
        padding: 30px;
        background:url(https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547122821339&di=e28b725cddbecf688cb827c96f726ab0&imgtype=0&src=http%3A%2F%2Fpic.51yuansu.com%2Fpic%2Fcover%2F00%2F24%2F02%2F57e3203eb1eb3_610.jpg);
        background-position: center;
        background-clip: content-box;
    }
</style>
<!-- DOM  -->
<div id="box"></div>

只填充content部分,不考虑padding和border


content-box
  1. text
<style>
/* css */
    #box{
        width: auto;
        font-size:120px;
        font-weight:bold;
        text-align: center;
        background:url(https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547122821339&di=e28b725cddbecf688cb827c96f726ab0&imgtype=0&src=http%3A%2F%2Fpic.51yuansu.com%2Fpic%2Fcover%2F00%2F24%2F02%2F57e3203eb1eb3_610.jpg) repeat;
        -webkit-background-clip:text; /* 注意这里 */
        -webkit-text-fill-color:transparent; /* 注意这里 */
    }
</style>
<!-- DOM  -->
<div id="box">霸气外漏</div>

设置文字遮罩的效果就是这么简单啦~But,很遗憾的是,不是所有浏览器都支持... 霸气外漏
上一篇下一篇

猜你喜欢

热点阅读