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;
相关推荐
Python智慧行囊1 小时前
前端三大件--HTML
css·python
软件技术NINI1 小时前
html css js网页制作成品——HTML+CSS珠海网页设计网页设计(4页)附源码
javascript·css·html
爱编程的鱼1 小时前
如何用CSS实现HTML元素的旋转效果:从基础到高阶应用
前端·css·html
Joker Zxc3 小时前
【前端基础】7、CSS的字体属性(font相关)
前端·css
酷小洋7 小时前
CSS基础
前端·css
梁下轻语的秋缘10 小时前
深入浅出HTML:构建现代网页的基石
前端·html
NoneCoder10 小时前
未来 CSS:变量、容器查询与新特性的探索
前端·css
患得患失94913 小时前
【前端】【总复习】HTML
前端·html
源码方舟20 小时前
【HTML5】显示-隐藏法 实现网页轮播图效果
前端·javascript·html·css3·html5
tq108620 小时前
CSS分栏布局
css