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;
相关推荐
用户938515635074 小时前
TypeScript 高级类型 + CSS 三列布局:从类型体操到样式工程的进阶之路
css·面试·typescript
Eason_Lou5 小时前
【无标题】
前端·vue.js·html
anOnion7 小时前
构建无障碍组件之Menu and Menubar Pattern
前端·html·交互设计
Highcharts11 小时前
全功能施工项目管理甘特图 Demo:任务依赖箭头、当前日期标线、周末高亮、分组项目可视化
html·数据可视化
IMPYLH12 小时前
HTML 的 <h1>–<h6> 元素
前端·javascript·html
IMPYLH12 小时前
HTML 的 <head> 元素
前端·html
梦醒沉醉13 小时前
2、HTML入门——HTML元信息
html
莫问ABC15 小时前
HTML、CSS、JavaScript 前端三件套
前端·css·html
fangzhanpeng16816 小时前
(前端)5.盒子模型的宽高和边距
前端·javascript·css
葡萄城技术团队16 小时前
告别宽表拖拽:SpreadJS 如何让 Web 表格承接 Excel 操作习惯
数据库·html·excel