zoukankan      html  css  js  c++  java
  • css之为文本添加线性渐变和外描边

    css之为文本添加线性渐变和外描边

     一、效果:

    描边:描边+渐变:

    二、描边:

    api:text-stroke

    问题:text-stroke的描边是居中描边,无法直接设置外描边

    解决:在before中添加文本,设置字体描边,绝对定位在文本下方

    代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            body{background:blue}
            h2 {
                font-size: 31px;
                font-weight: 800;
                color: #70b4d9;
                position: relative;
                z-index: 1;
            }
            h2::before {
                content: attr(data-text);
                position: absolute;
                -webkit-text-stroke: 6px #fff;
                z-index: -1;
            }
        </style>
    </head>
    <body>
        <h2 data-text="数据采集">数据采集</h2>
    </body>
    </html>
    

    三、添加渐变

    api:

    background-image:-webkit-gradient(linear,0% 0%, 0% 100%, from(#999999), to(#333333), color-stop(0.5,#336600));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;

    原理:字体渐变的原理是将背景图片剪切为字体,然后将字体颜色取消。

    问题:字体渐变的实质是背景图片,所以无法在其下面再垫一层背景

    解决:给文本套一层span,使渐变为span的背景,然后在父标签垫描边背景。

    代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            body{background:blue}
            h2 {
                font-size: 31px;
                font-weight: 800;
                color: #70b4d9;
                position: relative;
                z-index: 1;
            }
            h2>span{
                background-image:-webkit-gradient(linear,0% 0%, 0% 100%, from(#999999), to(#333333), color-stop(0.5,#336600));
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
            }
            h2::before {
                content: attr(data-text);
                position: absolute;
                -webkit-text-stroke: 6px #fff;
                z-index: -1;
            }
        </style>
    </head>
    <body>
        <h2 data-text="数据采集"><span>数据采集</span></h2>
    </body>
    </html>
    

      

    钻研不易,转载请注明出处、、、、、、

  • 相关阅读:
    The Sixth Assignment
    The fifth assigiment
    网络编程
    面向对象
    python数据类型之集合
    python数据类型之列表
    python数据类型之字符串
    python数据类型之字典
    python数据类型之元组
    常用模块
  • 原文地址:https://www.cnblogs.com/s313139232/p/10530634.html
Copyright © 2011-2022 走看看