表格背景(Background)图像CSS⽤法详解
序号中⽂说明标记语法
1背景颜⾊{background-color:数值}
2背景图⽚{background-image: url( )|none}
3背景重复{background-repeat:inherit|no-repeat|repeat|repeat-x|repeat-y}
4背景固定{background-attachment:fixed|scroll}
5背景定位{background-position:数值|top|bottom|left|right|center}
6背影样式{background:背景颜⾊|背景图象|背景重复|背景附件|背景位置}
1.背景颜⾊:background-color
语法: {background- color:数值}
说明: 参数取值和颜⾊属性⼀样
注意: 在HTML当中,要为某个对象加上背景⾊只有⼀种办法,那就是先做⼀个表格,在表格中设置完背景 ⾊,再把对象放进单元格。这样做⽐较⿇烦,不但代码较多,还要为表格的⼤⼩和定位伤些脑筋。现在⽤CSS就可以轻松地直接搞定了,⽽且对象的范围很⼴,可 以是⼀段⽂字,也可以只是⼀个单词或⼀个字母。
例⼦: <span >给部分⽂字加背景颜⾊</span>给部分⽂字加背景颜⾊
表格背影颜⾊:
2.背景图⽚:background-image
语法: {background-image: url( )|none}
说明:  URL就是背景图⽚的存放路径。如果⽤“none”来代替背景图⽚的存放路径,将什么也不显 ⽰。
例⼦: 给部分⽂字加背景图 ⽚ .imgbgstyle { background-image: url(/UploadFiles19/2007620145620734.gif)}
3.背景重复:background-repeat
语法: {background-repeat:inherit|no-repeat|repeat|repeat-x|repeat-y}
作⽤: 背景图⽚重复控制的是背景图⽚平铺与否,也就是说,结合背景定位的控制可以在⽹页上的某处单独 显⽰⼀幅背景图⽚
说明: 参数取值范围:
·inherit 继承
·no- repeat 不重复平铺背景图⽚
·repeatcss固定定位
·repeat-x 使图⽚只在⽔平⽅向上平铺
·repeat-y 使图⽚只 在垂直⽅向上平铺
注意: 如果不指定背景图⽚重复属性,浏览器默认的是背景图⽚向 ⽔平、垂直两个⽅向上平铺。
4.背景固定:background- attachment
语法: {background-attachment:fixed|scroll}
说明: 参数取值范围
·fixed:⽹页滚动时,背景图⽚相对于浏览器的窗⼝⽽⾔,固定不动
·scroll: ⽹页滚动时,背景图⽚相对于浏览器的窗⼝⽽⾔,⼀起滚动
注意: 背景图⽚固定控制 背景图⽚是否随⽹页的滚动⽽滚动。如果不设置背景图⽚固定属性,浏览器默认背景图⽚随⽹页的滚动⽽滚动。为了避免过于花哨的背景图⽚在滚动时伤害浏览者的 视⼒,所以可以解除背景图⽚和⽂字内容的捆绑,该为和浏览器窗⼝捆绑。
例⼦: 使 背景图案不随⽂字“滚动”的CSS
BODY { background: purple url(/UploadFiles19/2007620145640580.jpg); background-repeat:repeat-y; background-attachment:fixed }
5.背景定位:background-position
语法: {background- position:数值|top|bottom|left|right|center}
作⽤: 背 景定位⽤于控制背景图⽚在⽹页中显⽰的位置。
说明: 参数取值范围
·带长 度单位的数字参数
·top:相对前景对象顶对齐
·bottom:相对前景对象底对齐
·left:相对前景对象左对齐
·right: 相对前景对象右对齐
·center:相对前景对象中⼼对齐
·⽐例关系
关键字解释如下:
top left = left top = 0% 0%
top = top center = center top = 50% 0%
right top = top right = 100% 0%
left = left center = center left = 0% 50%
center = center center = 50% 50%
right = right center = center right = 100% 50%
bottom left = left bottom = 0% 100%
bottom = bottom center = center bottom = 50% 100%
bottom right = right bottom = 100% 100%
注意: 参数中的center如果⽤于另外⼀个参数的前⾯,表⽰⽔平居中;如果⽤于另外⼀个参数的后 ⾯,表⽰垂直居中。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。