CSS设置DIV背景色渐变显示

html-css09

CSS设置DIV背景色渐变显示,第1张

01

打开软件

可以使用Dreamweaver或Visual studio软件,比如打开VS软件,如下图所示:

02

创建一个DIV

然后在body主体中创建一个div名为【a】, <div class="a">DIV</div>,如下图所示:

03

设置属性

然后设置div的属性,比如高度、宽度和颜色等等,如下图所示:

04

背景渐变色

然后设置背景渐变色,代码如下图:

background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#0000ff))

其中:linear-gradient()是用来创建线性渐变的语句。

05

预览效果

点击预览图标,在浏览器中的显示效果图如下所示:

1、语法

2、参数

第一个参数:指定渐变方向,可以用“角度”的关键词或“英文”来表示:

第一个参数省略时,默认为“180deg”,等同于“to bottom”。

第二个和第三个参数,表示颜色的起始点和结束点,可以有多个颜色值。

例如:

background-image:linear-gradient(to left, red,orange,yellow,green,blue,indigo,violet)

该属性已经得到了 IE10+、Firefox19.0+、Chrome26.0+ 和 Opera12.1+等浏览器的支持。

CSS linear-gradient() 函数用于创建一个表示两种或多种颜色线性渐变的图片。其结果属于<gradient>数据类型,是一种特别的<image>数据类型。

linear-gradient( [ <angle>| to <side-or-corner>,]? <color-stop-list>)

  \---------------------------------/ \----------------------------/

    Definition of the gradient line        List of color stops 

where <side-or-corner>= [ left | right ] || [ top | bottom ]

  and <color-stop-list>= [ <linear-color-stop>[, <color-hint>? ]? ]#, <linear-color-stop>

  and <linear-color-stop>= <color>[ <color-stop-length>]?

  and <color-stop-length>= [ <percentage>| <length>]{1,2}

  and <color-hint>= [ <percentage>

栗子:

div {

  background: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet)

}