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;
相关推荐
lastknight12 小时前
CSS @layer
前端·css
weixin_4398575414 小时前
借助AI制作的贪吃蛇游戏(单HTML文件)
游戏·html·ai编程
用户0595401744617 小时前
用 Pytest 接管大模型记忆存储测试,状态一致性问题减少 90%
前端·css
LaughingZhu2 天前
Product Hunt 每日热榜 | 2026-07-17
前端·数据库·人工智能·经验分享·mysql·chatgpt·html
天若有情6732 天前
纯HTML+Tailwind单页作品集网站——零框架静态前端完整源码
前端·html
甜味弥漫2 天前
一文搞懂 Flex 弹性布局:为什么它成为现代 CSS 布局的首选?
css
qq_419854052 天前
空间网格管理器
前端·javascript·html
天若有情6732 天前
Dev_Portfolio 个人主页html网页源码分享!!!
前端·html·源码·个人主页
云水一下2 天前
零基础玩转 bWAPP 靶场(五):HTML 注入——存储型(博客)
web安全·html·bwapp·存储型注入
芯日记3 天前
Mac-使用文本编辑的html浏览器打开出现源代码问题
macos·html