CSS - 实现对角渐变边框的方法

实现对角渐变边框

border-image-source

在这里插入图片描述
这种方式虽然简单但有个明显的缺陷,不支持设置border-radius ,外框想设置成圆角需要加:
在这里插入图片描述

clip-path: inset(0 round 10px);

优点: 内容背景可以透明

 .box{
        width: 150px;
        height: 150px;
        background: #ccc;
		border: 4px solid;
  		border-image-source: linear-gradient(to right top, #00FFAD,  #00ffae0f, #00ffae0f, #00FFAD);
 		border-image-slice: 1;
    }

background 背景

一、

在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS3 box-shadow属性示例- 基础教程(cainiaojc.com)</title>
<style>
    .box{
        width: 150px;
        height: 150px;
        border: 0px solid #999;
		border-radius: 5px;  
  		position: relative;
  		background-color: white;  
	}
	.box::before{
  	 content: '';
 	 position: absolute;
  	 top: -2px; right: -2px; bottom: -2px; left: -2px;/* 边框宽度 */
 	 border-radius: 5px; 
	 background: linear-gradient(to right top, #00FFAD,  #00ffae0f, #00ffae0f, #00FFAD);  /*对角渐变*/
  	 z-index: -1;/* 置于内容之下 */ 
}
	

	
	.shadow{
    }
    .shadow-inside{
        box-shadow: inset 0 0 6px 2px #999;
    }
</style>
</head>
<body>
    <h2>Box Shadow</h2>
    <div class="box shadow"></div>
    <br>
    <h2>Box Shadow Inside</h2>
    <div class="box shadow-inside"></div>
</body>
</html>

二、

在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>边框渐变色</title>
  </head>
  <body>
    <div class="container">
      <div class="box">
        <span></span>
        <p>content</p>
      </div>
      <div class="box">
        <span></span>
        <p>content</p>
      </div>
    </div>
  </body>
</html>
<style>
  * {
    padding: 0;
    margin: 0;
  }
  .container {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 1);
  }
  .box {
    position: relative;
    width: 120px;
    height: 160px;
    margin: 60px;
    border-radius: 10px;
  }
  /* 通过伪类覆盖背景渐变色 */
  .box::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    background: linear-gradient(45deg, #00e5ff, #00ff66, #aeff00, #ffd000);
  }
  /* 通过伪类实现虚化渐变色 */
  .box::before {
    content: '';
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    position: absolute;
    background: linear-gradient(45deg, #00e5ff, #00ff66, #aeff00, #ffd000);
    filter: blur(40px);
  }
  /* 覆盖内部区域,做出边框效果 */
  .box span {
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    bottom: 4px;
    border-radius: 6px;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 3;
  }
  /* 真实的内容区 */
  .box p {
    position: absolute;
    z-index: 5;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
  }
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值