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;
相关推荐
咖啡虫1 小时前
css中的3d使用:深入理解 CSS Perspective 与 Transform-Style
前端·css·3d
雯0609~3 小时前
html:文件上传-一次性可上传多个文件,将文件展示到页面(可删除
前端·html
天天扭码4 小时前
项目登录注册页面太丑?试试我“仿制”的丝滑页面(全源码可复制)
前端·css·html
谁还不是一个打工人4 小时前
css解决边框四个角有颜色
前端·css
allen_19989 小时前
掘金的广告越来越烦人了,悄悄把它隐藏起来🤫
前端·css·掘金社区
leolee1810 小时前
Tailwind CSS 简述
前端·css
Json_10 小时前
智慧酒店官网-前端静态网站模板【前端练习项目】
前端·css·html
Python智慧行囊11 小时前
前端开发基础:HTML 与 CSS 入门详解
前端·css·html
调试大师(八岁习武)11 小时前
前端开发中的问题排查与定位:HTML、CSS、JavaScript(报错的解决方式)
javascript·css·html
YYDS31412 小时前
坦克大战HTML网页游戏 (永久免费)
javascript·游戏·html