css渐变圆角边框

项目场景:

渐变圆角边框


问题描述:

无法给一个圆角的div加上渐变的边框

border-image 存在缺陷不支持圆角
使用完 border-image 之后,border-radius 设置是无效的,达不到圆角的效果


解决方案:

background-image/background-clip

 <div class="outBor">
        <div class="content">
            <span>内容区域</span>
        </div>
    </div>
  
html,body{
        background-color: rgb(51, 50, 50);
    }
    .outBor{
        width: 360px;
        height: 150px;
        padding: 1px;
        display: flex;
        justify-content: center;
        align-items: center;
        border: none;
       background-color: transparent;
       box-sizing:border-box;
         /* 这里需要设置两个背景,第一个背景是内容区域的背景,另一个是实现渐变边框的背景 */
       background-image: linear-gradient(100deg,rgba(29,39,34,0.8)0.94%,rgba(54,87,79,0.8) 94.7%),linear-gradient(to bottom right,  #0fd850, #f9f047);
       border-radius: 12px;
        /* 背景裁切的时候,第一个背景需要从内容区域开始裁切,因此设置为content-box;
        第二个背景需要作为渐变边框,因此需要从边框处开始裁切 */
       background-clip: content-box,padding-box;
    }
    .content{
        width: 359px;
        height: 148px;
        padding:15px;
        color: #f1f1ee;
        display: flex;
        justify-content: center;
        align-items: center;
    }

渐变

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值