css实现圆角+渐变+半透边框

效果图

div结构

<div class="box"></div>

css分解

  1. 基础结构

    .box{
    	position:relative;
        width:200px;
        height:200px;
        box-sizing:border-box;
        padding:1px; //1px内边距作为1px边框使用
    }
    
  2. 加入大背景(红色渐变边框)

    .box{
    	background-image: linear-gradient(146deg, rgba(255, 252, 252, 0.60) 0%, rgba(255, 235, 235, 0.77) 100%);
    }
    
  • 此时的效果图

在这里插入图片描述

  1. 使用伪元素加入内容背景

    .warning::before {
        content: '';
        position: absolute;
        top: 1px;
        right: 1px;
        bottom: 1px;
        left: 1px;
        background-color: rgba(255, 252, 252, 80%);
        border-radius: 8px;
    }
    
  • 覆盖上去后的效果图

在这里插入图片描述

如果内容不需要透明,将伪元素背景换成纯色即可

方案二:图片边框

图片

喊ui设计师交出一张边框的切图
在这里插入图片描述

css

.box {
    position: relative;
    width: 260px;
    height: 260px;
    border-radius: 8px;
	/* 下面这个是内容的渐变背景 */
    background-image: linear-gradient(146deg, rgba(255, 252, 252, 0.60) 0%, rgba(255, 235, 235, 0.77) 100%);
}

.box::before {
    content: '';
    position: absolute;
    border: 15px solid transparent; /* 根据图片大小调整边框粗细 */
    /* 引入图片 并设置拉伸 */
    border-image: url('./border-warning.png') 50 stretch;
    /* 100%布局 */
    top: 0px;
    right: 0px;
    bottom: 0px;
    left: 0px;
    border-radius: inherit;
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值