css 实现边框渐变色(一组对角是深色,另外一组对角是浅色)

需求:想要一个边框是渐变色的(一组对角是深色,另外一组对角是浅色)

   <style>
	.gradient-border {
		margin-left: 20px;
		margin-top: 40px;
		position: relative;
		width: 400px;
		height: 300px;
		padding: 20px;
		box-sizing: border-box;
		text-align: center;
		font-size: 16px;
		color: #333;
		z-index: 1;
		background-color: pink;
	}

	.gradient-border::before,
	.gradient-border::after {
		content: '';
		position: absolute;
		z-index: -1;
	}

	.gradient-border::before {
		top: -10px;
		left: -10px;
		right: -10px;
		bottom: -10px;
		border-radius: 5px;
		background:
			linear-gradient(to right, #7b99cb, #d5e0f0) top / 100% 2px no-repeat,
			linear-gradient(to right, #dde0ed, #597bbd) bottom / 100% 2px no-repeat,
			linear-gradient(to bottom, #8aa9d7, #dfe4f2) left / 2px 100% no-repeat,
			linear-gradient(to bottom, #d5e0f0, #537cb7) right / 2px 100% no-repeat;
	}
</style>



<div class="gradient-border">这是一个有渐变边框的盒子</div>

 


还有一个图例,是两个顶角的颜色

 

<style>
            .box {
				position: relative;
				width: 200px;
				height: 200px;
				background-color: lightpink;
				text-align: center;
				padding: 30px;
				/* 背景颜色可以根据需要更改 */
			}

			.box::after {
				content: '';
				position: absolute;
				width: 50%;
				height: 50%;
				border-style: solid;
				border-width: 0 5px 5px 0;
				/* 设置边框宽度 */
			}

			.box::before {
				content: '';
				position: absolute;
				width: 50%;
				height: 50%;
				border-style: solid;
				border-width: 5px 0 0 5px;
				/* 设置边框宽度 */
			}

			.box::before {
				top: 0;
				left: 0;
				border-color: blue transparent transparent blue;
				/* 左上角蓝色边框 */
			}

			.box::after {
				bottom: 0;
				right: 0;
				border-color: transparent red red transparent;
				/* 右下角红色边框 */
			}
</style>




<div class="box">对角颜色的盒子</div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值