前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CSS 3.0中的混合模式的妙用

CSS 3.0中的混合模式的妙用

作者头像
越陌度阡
发布2020-11-26 11:21:59
5640
发布2020-11-26 11:21:59
举报

给大家分享一个用CSS 3.0的混合模式实现的特效,不用给文字设置多种颜色,滚动页面时,能够让文字能够根据背景颜色自动发生改变,效果如下:

以下是代码实现,欢迎大家复制粘贴和收藏。

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>CSS 3.0中的混合模式的妙用</title>
        <style>
            * {
                margin: 0;
                padding:0;
            }

            .content,
            .wrapper:before {
                box-sizing: border-box;
                display: block;
                font-size: 4em;
                padding: 1em;
                width: 6em;
                height: 3em;
                position: fixed;
                top: 50%;
                left: 50%;
                transform: translate3d(-50%, -50%, 0);
            }

            .content {
                font-weight: bold;
                text-align: center;
                z-index: 1000;
                background: #fff;
                color: #000;
                mix-blend-mode: lighten;
                padding: 0.6rem;
            }

            section {
                background-repeat: no-repeat;
                background-size: cover;
                isolation: isolate;
                position: relative;
                height: 100vh;
                padding: 1em;
            }

            .wrapper {
                clip: rect(auto auto auto auto);
                position: absolute;
                top: 0;
                right: 0;
                bottom: 0;
                left: 0;
            }

            .wrapper:before {
                content: " ";
                padding: 2em 3.5em;
                mix-blend-mode: darken;
            }

            .one {
                background-image: url(https://source.unsplash.com/1920x1080?city);
            }

            .one .wrapper:before {
                background: red;
            }

            .two {
                background-image: url(https://source.unsplash.com/1920x1080?landscape);
            }

            .two .wrapper:before {
                background: #faaa54;
                mix-blend-mode: difference;
            }

            .three {
                background-image: url(https://source.unsplash.com/1920x1080?portrait);
            }

            .three .wrapper:before {
                background: #6c320a;
                mix-blend-mode: screen;
            }

            .four {
                background-image: url(https://source.unsplash.com/1920x1080?stars);
            }

            .four .wrapper:before {
                background: #e4135d;
            }
        </style>
    </head>

    <body>
        <div class="content">文字颜色自适应背景</div>
        <section class="one">
            <div class="wrapper"></div>
        </section>
        <section class="two">
            <div class="wrapper"></div>
        </section>
        <section class="three">
            <div class="wrapper"></div>
        </section>
        <section class="four">
            <div class="wrapper"></div>
        </section>
    </body>

</html>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/06/10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档