CSS实验:linear-gradient 实现「四角边框」和「 字体渐变」

background: linear-gradient(red, yellow, blue);

background: linear-gradient(red 0%, yellow 50%, blue 100%);

background: linear-gradient(to right, red 0%, yellow 50%, blue 100%);

background: linear-gradient(90deg, red 0%, yellow 50%, blue 100%);

to right代表渐变偏移角度,to right (相当于90deg)

1、四角边框的背景

这里我们使用linear-gradient方式实现,结合background一些其他属性,可以更加灵活。下面的方式是用linear-gradient画线的方式,画上下两条边,然后通过background-size的方式截取边角上的部分,组合形成的。

复制代码
width: 200px;
height: 200px;
padding: 10px;
background-origin: content-box;
background-color: #0e294c;
background-image: 
	linear-gradient(#4cc7f3 2px, transparent 2px, transparent calc(100% - 2px), #4cc7f3 calc(100% - 2px), #4cc7f3 100%),
	linear-gradient(90deg, #4cc7f3 2px, transparent 2px, transparent calc(100% - 2px), #4cc7f3 calc(100% - 2px), #4cc7f3 100%),
	linear-gradient(#4cc7f3 2px, transparent 2px, transparent calc(100% - 2px), #4cc7f3 calc(100% - 2px), #4cc7f3 100%),
	linear-gradient(90deg, #4cc7f3 2px, transparent 2px, transparent calc(100% - 2px), #4cc7f3 calc(100% - 2px), #4cc7f3 100%);
background-repeat: no-repeat;
background-position: top left, top left, bottom right, bottom right;
background-size: 10px 100%, 100% 10px;
相关推荐
今天AI了吗4 小时前
2026年三大AI桌面智能体横评:Codex vs Hermes vs WorkBuddy
大数据·前端·css·人工智能·架构
HwJack205 小时前
用 HML + CSS + JS 三段式写鸿蒙界面
javascript·css·harmonyos
zhanghaha13148 小时前
HTML系列教程:15_标签 全称 + 简写 超详细讲解(新手专用)
前端·html
IMPYLH8 小时前
HTML 的 <samp> 元素
前端·网络·html
IMPYLH8 小时前
HTML 的 <script> 元素
前端·html
豆约翰21 小时前
css自制图书封面效果
前端·css
CoderYanger1 天前
前端基础——JavaScript(WebAPI)代码案例
java·开发语言·前端·javascript·css·前端框架·html5
IMPYLH1 天前
HTML 的 <s> 元素
前端·html
晴天161 天前
HTML iframe 标签全面解析:原理、属性、实战场景与最佳实践
前端·html·状态模式
晴天161 天前
Chrome 控制台(DevTools)竟是用 HTML 写的?-Day41
前端·chrome·html