Getting web front-end to combat: CSS3 Create text background

Bring gradient text, or let the text revealing picture. These effects CSS attributes can also be completed.

A method using CSS3 properties mix-blend-mode: lighten; implemented

Use mix-blend-mode can be easily achieved, we only need to construct a black text, white background text div, is superimposed on the picture, then use the mix-blend-mode can simply works as follows:

Getting web front-end to combat: CSS3 Create text background

The core code is as follows:

<div class="container">
    <div class="pic"></div>
    <div class="text">IMAGE</div>
</div>
.pic {
    position: relative;
    width: 100%;
    height: 100%;
    background: url($img);
    background-repeat: no-repeat;
    background-size: cover;
}

.text {
    position: absolute;
    width:100%;
    height:100%;
    color: #000;
    mix-blend-mode: lighten;
    background-color: #fff;
}
专门建立的学习Q-q-u-n ⑦⑧④-⑦⑧③-零①②  分享学习方法和需要注意的小细节,互相交流学习,不停更新最新的教程和学习技巧(从零基础开始到WEB前端项目实战教程,学习工具,全栈开发学习路线以及规划)

Method two, -webkit-background-clip: text;

Use of this property means that the block of text within a cropping region cropping outwardly, Background, namely the text block, an area other than the text will be clipped.

<div class="pic2">
    image
</div>
.pic2{
    width: 500px;
    height: 500px;
    margin: 40px auto;
    background: url("1.jpg") no-repeat center center;
    background-size: cover;
    font-size: 120px;
    font-weight: bold;
    text-align: center;
    line-height: 500px;
    /*很重要*/
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

Cons: only supports webkit browser kernel, poor compatibility.

Guess you like

Origin blog.51cto.com/14592820/2467585