当前位置: 首页 > news >正文

【css】渐变

渐变是设置一种颜色或者多种颜色之间的过度变化。

两种渐变类型:

  • 线性渐变(向下/向上/向左/向右/对角线)

  • 径向渐变(由其中心定义)

1、线性渐变

语法:background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
其中direction是方向,值可以有bottom、right、top、left 。如果该参数参数值前面添加了to,则是渐变沿着相应的方向移动。如果省略了to,则为两个参数组合的方向,比如bottom right:右下角方向。
其中从上到下是默认的方向,可以不用添加direction参数。
1.1 默认方向
代码:

<head>
<style>
#grad1 {height: 200px;background-color: blue; /* 针对不支持渐变的浏览器 */background-image: linear-gradient(blue, yellow);
}
</style>
</head>
<body><div id="grad1"></div></body>

渲染效果:
在这里插入图片描述
1.2、从左到右

代码:

<head>
<style>
#grad1 {height: 200px;background-color: blue; /* 针对不支持渐变的浏览器 */background-image: linear-gradient(to right,blue, yellow);
}
</style>
</head>
<body><div id="grad1"></div></body>

渲染效果:
在这里插入图片描述
1.3 右下角
代码:

<style>
#grad1 {height: 200px;background-color: blue; /* 针对不支持渐变的浏览器 */background-image: linear-gradient(to bottom right,blue, yellow);
}
</style>
</head>
<body><div id="grad1"></div></body>

渲染效果:
在这里插入图片描述

2、径向渐变
径是指圆形的直径的径,以圆心为出发点,沿着径向渐变,和箭靶的效果差不多。
语法:

/* 在容器中心的渐变,从红色开始,变成蓝色,最后变成绿色 */
radial-gradient(circle at center, red 0, blue, green 100%)

边缘形状可以是圆形(circle)或椭圆形(ellipse)

形式语法

<radial-gradient()> = radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )  <size> = <extent-keyword>              |<length [0,∞]>                |<length-percentage [0,∞]>{2}  <position> = [ left | center | right ] || [ top | center | bottom ]  |[ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]?  |[ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ]  <color-stop-list> = <linear-color-stop> , [ <linear-color-hint>? , <linear-color-stop> ]#  <extent-keyword> = closest-corner   |closest-side     |farthest-corner  |farthest-side    <length-percentage> = <length>      |<percentage>  <linear-color-stop> = <color>               &&<length-percentage>?  <linear-color-hint> = <length-percentage>  

代码:

<style>
#grad1 {height: 200px;width:200px;background-color: blue; /* 针对不支持渐变的浏览器 */background-image: radial-gradient(circle at center,#33691e, yellow);
}
</style>
</head>
<body><div id="grad1"></div></body>

渲染效果:
在这里插入图片描述
关于径向渐变的详细介绍可以参考MDN Web Docs社区

http://www.lryc.cn/news/115892.html

相关文章:

  • idea打开多个项目需要开多个窗口(恢复询问弹窗)
  • 篇十三:策略模式:选择不同算法
  • Centos7.6 安装mysql过程全记录
  • Java中的Guava是什么?
  • vue.js兄弟组件方法调用b组件调用a组件方法
  • 【Kubernetes】二进制搭建
  • 【MFC】08.MFC消息,自定义消息,常用控件(MFC菜单创建大总结),工具栏,状态栏-笔记
  • Clickhouse 数据存储
  • c语言每日一练(3)
  • java基础-Stream(流)、File(文件)和IO
  • el-table实现指定列合并
  • 38.利用matlab解 有约束无约束的参数估计对比(matlab程序)
  • 什么是React?React与VU的优缺点有哪些?
  • 区块链技术助力慈善,为您的善举赋予全新力量!
  • 模拟实现消息队列项目(系列4) -- 服务器模块(内存管理)
  • STM32 LoRa源码解读
  • 【BASH】回顾与知识点梳理(十)
  • 【网络】应用层——HTTPS协议
  • Windows新版文件资源管理器经常在后台弹出的临时解决方案
  • 软考高项(八)项目整合管理 ★重点集萃★
  • 基于python+django开发的学生信息管理系统
  • mysql的高级查询语句
  • 04-8_Qt 5.9 C++开发指南_QTableWidget的使用
  • 《golang设计模式》第二部分·结构型模式-01-适配器模式(Adapter)
  • 机器学习概述及其主要算法
  • 识jvm堆栈中一个数据类型是否为为引用类型,目前虚拟机实现中是如何做的?
  • Bug合集
  • linux下.run安装脚本制作
  • 面试热题(翻转k个链表)
  • 前端面试的性能优化部分(4)每天10个小知识点