CSS3

CSS3 知识量:11 - 43 - 138

4.1 背景基本知识><

背景的基本属性- 4.1.1 -

背景主要包括5个基本属性:

  • background-color 背景颜色。

  • background-image 背景图片。

  • background-repeat 背景图片展示方式。

  • background-attachment 背景图片固定还滚动。

  • background-position 背景图片位置。

CSS3中关于背景新增了4个属性:

  • background-origin 指定绘制背景图片的起点。

  • background-clip 指定背景图片的显示范围。

  • background-size 指定背景图片的尺寸大小。

  • background-break 指定内联元素的背景图片进行平铺时的循环方式。

background-color- 4.1.2 -

background-color语法为:

background-color:transparent||<color>

默认值为transparent,即透明的。

<color>用于设置具体颜色。其取值有以下格式:

  • 颜色名,例如:red、blue。

  • rgb色,例如:rgb(255,255,0)或rgb(50%,100%,0%)。

  • rgba色,例如:rgba(255,255,0,0.5),与rgb相比,多了透明度参数。

  • hls值,例如:hsl(0,90%,50%)。

  • 十六进制值,例如:#ff00ff。

background-image- 4.1.3 -

background-image的语法为:

background-image:none||<url>

默认值为none,表示没有背景图片。

<url>用于指明背景图片的地址,可以是相对地址,也可以是绝对地址。

background-repeat- 4.1.4 -

background-repeat的语法为:

background-repeat:repeat||repeat-x||repeat-y||no-repeat

参数简要说明如下:

  • repeat 是默认值,即背景图片将沿元素的X轴和Y轴同时平铺。

  • repeat-x 表示背景图片沿元素的X轴平铺,Y轴不进行任何铺放。

  • repeat-y 表示背景图片沿元素的Y轴平铺,X轴不进行任何铺放。

  • no-repeat 表示背景图片不做任何铺放,与repeat正好相反。

background-attachment- 4.1.5 -

background-attachment的语法为:

background-attachment:scroll||fixed

该属性用于设置背景图片是否随着页面的其余部分滚动。其默认值为scroll(滚动)。值为fixed时,背景图片将固定不动。fixed值常用于html或body标签上。

background-position- 4.1.6 -

background-position的语法为:

background-position:<percentage>||<length>||[left|center|right][,top|center|bottom]

该属于用于设置背景图片的位置,默认值是:(0,0)||(0%,0%)||(left top),即左上角。可以使用关键字left、center、right的组合,创建9种不同的位置。也可以使用百分比的方式,进行更多更细致的设置。