16.纯 CSS 创作一个渐变色动画边框

原文地址:https://segmentfault.com/a/1190000014785816

感想:边框是伪元素::after来的;

HTML代码:

<div class="box">
    you are my<br>
    FAVORIFE
</div>

CSS代码:

html, body,.box {
    margin: 0;
    padding: 0;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
body{
    background: #222;
}
.box{
    width: 10em;
    height: 5em;
    border-radius: 0.2em;
    line-height: 1.5em;
    font-size: 2.5em;
    /* 字体系列:无衬线;*/
    font-family: sans-serif;
    color: white;
    background: #111;
    position: relative;
    animation: animate_text 2s linear infinite alternate;
}
@keyframes animate_text{
    from{
        color: lime;
    }
    to{
        color: yellow;
    }
}
/* 用伪圆增加一个背板 */
.box::after{
    content: '';
    position: absolute;
    width: 102%;
    height: 104%;
    background-image: linear-gradient(60deg, aquamarine, cornflowerblue, goldenrod, hotpink, salmon, lightgreen, sandybrown, violet);
    background-size: 300%;
    border-radius: 0.2em;
    z-index: -1;
    animation: animate_bg 5s infinite;
}
@keyframes animate_bg{
    0%{
        background-position: 0%, 50%;
    }
    50%{
        background-position: 100%, 50%;
    }
    100%{
        background-position: 0%, 50%;
    }
}

 

posted on 2019-01-08 21:22  人生与戏 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/FlyingLiao/p/10241519.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值