css渐变属性有几种(css设置渐变背景色的方法)
页面中如果有两种或多种指定颜色之间的平滑过渡的渐变效果,会使得我们的视觉效果瞬间提升几个档次,在CSS3中有提供的多个渐变方式属性就能让我们轻松实现这样的渐变效果。
目前CSS渐变属性有六个,分别为:linear-gradient(线性渐变),repeating-linear-gradient(重复线性渐变),radial-gradient(径向渐变),repeating-radial-gradient(重复径向渐变),conic-gradient(锥形渐变),repeating-conic-gradient(重复锥形渐变); CSS渐变属性作用是从一种颜色平滑渐变到另一种颜色的图像,那么background-image和border-image属性都可以用渐变作为图片内容。 下面,我们就分别来看看这几个属性的效果
linear-gradient和repeating-linear-gradient
线性渐变以直线的方式,可向左、向右、向上、向下、对角方向延伸,使用频率很高。要创建线性渐变,需要指定两种及以上的颜值和方向,如果未指定方向,默认为上到下渐变。
使用语法:
1 | background-image: linear-gradient(direction, ColorStop1, ColorStop2, ...,ColorStopN); |
1 2 3 4 5 6 7 8 | <div class="bg"> </div> .bg{ width: 200px; height: 200px; background-image: linear-gradient( rgb(123, 255, 0),rgb(119, 0, 255)); } |
默认从上到下
1 2 3 4 5 | .bg{ width: 200px; height: 200px; background-image: linear-gradient(to bottom right, rgb(123, 255, 0),rgb(119, 0, 255)); } |
指定方向从左上角到右下角
1 2 3 4 5 | .bg{ width: 200px; height: 200px; background-image: linear-gradient(to bottom right, rgb(123, 255, 0),rgb(119, 0, 255),rgb(255, 0, 43)); } |
指定方向从左上角到右下角,设置多种渐变颜色
1 2 3 4 5 | .bg{ width: 200px; height: 200px; background-image: linear-gradient(to bottom right, rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)); } |
指定方向从左上角到右下角,设置多种渐变颜色及颜色作用位置
repeating-linear-gradient用得可能比较少,它是基于linear-gradient进行重复平铺操作
1 2 3 4 5 | .bg{ width: 200px; height: 200px; background-image: repeating-linear-gradient(to bottom, rgb(123, 255, 0) 0 ,rgb(251, 255, 0)10%,rgb(255, 0, 43)15%); } |
前面都是渐变背景,我们再来看看渐变边框是什么效果
1 2 3 4 5 6 7 | .bg{ width: 200px; height: 200px; border-width:10px; border-style:solid; border-image:linear-gradient(to bottom right, rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)) 1 10; } |
radial-gradient
径向渐变以由中心点由圆或者椭圆向外扩散,使用语法
1 | background-image: radial-gradient(shape size at position, ColorStop, ..., ColorStopN); |
radial-gradient的用法和linear-gradient的用法相似
1 2 3 4 5 | .bg{ width: 200px; height: 200px; background-image: radial-gradient( rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)); } |
1 2 3 4 5 6 7 | .bg{ width: 200px; height: 200px; border-width:10px; border-style:solid; border-image:radial-gradient(rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)) 1 10; } |
conic-gradient
一般情况下,用conic-gradient的场景比较少,但我们也可以基本了解一下。其基本语法:
1 | background-image: conic-gradient(from angle at position,ColorStop, ...,ColorStopN); |
1 2 3 4 5 | .bg{ width: 200px; height: 200px; background-image: conic-gradient( rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)); } |
1 2 3 4 5 | .bg{ width: 200px; height: 200px; background-image: conic-gradient(from 90deg at left, rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)); } |
1 2 3 4 5 6 7 | .bg{ width: 200px; height: 200px; border-width:10px; border-style:solid; border-image:conic-gradient(from 90deg at left, rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)) 1 10; } |
其他文章
- 金山网盾一键修复(金山网盾防火墙)
- 中国七大常委
- 呼和浩特网上车管所与呼和浩特车管所考试查询
- 西安限行最新规定2020及西安机动车限号查询
- 广东发展银行信用卡余额查询方法
- 三亚租车哪家好与三亚租车公司价格
- 木马有哪些和木马有什么特点详解
- 高速免费时间与高速免费节日和节假日免费
- 聊城交警网违章查询与交通违章查询网及车辆违章查询
- 银行闹“钱荒” 家庭保险及早规划
- 太平洋人寿保险公司怎么样
- 广东省工伤保险条例全文及实施细则
- 怎么查询京东快递单号及京东运单编号查询快递
- 平安一账通手机登录及平安一账通官网
- 汽车保险杠修复步骤
- 网上购买汽车保险靠谱吗?
- 镇江交通违章查询网与镇江车管所违章查询
- 嘉禾人寿保险股份有限公司简介
- 易宝支付是什么和易宝支付怎么样详解
- 泉州住房公积金查询方法
- 旅游保险价格是多少
- 长沙地铁2号线线路图及长沙地铁规划图
- 邮政快递单号查询与如何查询邮政快递单号
- 南昌地铁3号线开建消息及南昌地铁3号线线路图
- 中国银行网上银行开通三种方法
- 五险一金怎么交?五险一金办理流程
- 深圳前海港货中心12月7日开业及年底还有日韩馆
- 什么是娱乐宝?娱乐宝和保险理财产品有什么区别?
- 海口租车哪家好与海口租车公司价格
- 金华交通违章查询网与金华交警支队违章查询