zoukankan      html  css  js  c++  java
  • [CSS]background背景

    css背景样式

    序号  中文说明  标记语法  
    1  背景颜色  {background-color:数值}  
    2  背景图片  {background-image: url('imgpath/img.png')|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 style="background-color:red">给部分文字加背景颜色</span>给部分文字加背景颜色

    表格背影颜色:style="background-color:red" 

    2.背景图片:background-image 

    语法: {background-image: url(http://www.jb51.net/URL)|none}
    说明: URL就是背景图片的存放路径。如果用“none”来代替背景图片的存放路径,将什么也不显示。
    例子: 给部分文字加背景图片 .imgbgstyle { background-image: url(http://www.jb51.net/logo.gif)}

    3.背景重复:background-repeat 

    语法: {background-repeat:inherit|no-repeat|repeat|repeat-x|repeat-y}
    作用: 背景图片重复控制的是背景图片平铺与否,也就是说,结合背景定位的控制可以在网页上的某处单独显示一幅背景图片
    说明: 参数取值范围:
    ·inherit 继承 
    ·no-repeat 不重复平铺背景图片
    ·repeat
    ·repeat-x 使图片只在水平方向上平铺 
    ·repeat-y 使图片只在垂直方向上平铺 
    注意: 如果不指定背景图片重复属性,浏览器默认的是背景图片向水平、垂直两个方向上平铺。

    4.背景固定:background-attachment 

    语法: {background-attachment:fixed|scroll}
    说明: 参数取值范围
    ·fixed:网页滚动时,背景图片相对于浏览器的窗口而言,固定不动 
    ·scroll:网页滚动时,背景图片相对于浏览器的窗口而言,一起滚动 
    注意: 背景图片固定控制背景图片是否随网页的滚动而滚动。如果不设置背景图片固定属性,浏览器默认背景图片随网页的滚动而滚动。为了避免过于花哨的背景图片在滚动时伤害浏览者的视力,所以可以解除背景图片和文字内容的捆绑,该为和浏览器窗口捆绑。 
    例子: 使背景图案不随文字“滚动”的CSS
    BODY { background: purple url(http://www.jb51.net/bg.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如果用于另外一个参数的前面,表示水平居中;如果用于另外一个参数的后面,表示垂直居中。 
  • 相关阅读:
    Study Plan The Twelfth Day
    Study Plan The Fifteenth Day
    Study Plan The Seventeenth Day
    Study Plan The Tenth Day
    Study Plan The Eighth Day
    Study Plan The Eleventh Day
    Study Plan The Sixteenth Day
    Study Plan The Thirteenth Day
    Study Plan The Fourteenth Day
    Study Plan The Ninth Day
  • 原文地址:https://www.cnblogs.com/cloudshadow/p/3625327.html
Copyright © 2011-2022 走看看