欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CSS下背景屬性background的使用方法

  發(fā)布時(shí)間:2011-01-05 23:15:04   作者:佚名   我要評(píng)論
背景屬性是給網(wǎng)頁添加背景色或者背景圖所用的CSS樣式,它的能力遠(yuǎn)遠(yuǎn)超于html之上。

背景顏色(background-color)


    CSS可以用純色來作為背景,也可以將背景設(shè)置為透明,background相當(dāng)于xhtml中的bgcolor。

它的兩個(gè)值:

  •     transparent(默認(rèn)值,透明)
  •     color(指定的顏色,和文本顏色的設(shè)置方法相同)


示例:


  body {background-color: black;}

    h1 {background-color: #00ff00;}

    h2 {background-color: transparent;}

    p {background-color: rgb(0,0,255);}


背景圖片(background-image)


    用一張圖片作為標(biāo)簽的背景可用到這個(gè)屬性,如果背景顏色和背景圖片都被定義了,背景圖片會(huì)覆蓋在背景顏色之上。

示例:


  body {background-image:url(../images/background.jpg);}

    或

  <body style="background-image:url(../images/background.jpg);">


背景重復(fù)屬性(background-repeat)


    這個(gè)屬性必須跟在background-image屬性后使用,它決定圖片背景的重復(fù)方法。如果使用了background-image后沒有添加這個(gè)屬性,默認(rèn)情況它是橫向縱向都重復(fù)的,它有四個(gè)屬性值:

  •     repeat(默認(rèn)值,重復(fù),橫向和縱向。)
  •     no-repeat(不重復(fù))
  •     repeat-x(背景圖片橫向重復(fù))
  •     repeat-y(背景圖片縱向重復(fù))


示例:


  body {

    background-image:url(../images/background.jpg);

    background-repeat:repeat-y; /*垂直重復(fù)*/

    }


背景位置屬性(background-position)


    這個(gè)屬性也是跟在background-image屬性后使用的,它決定背景圖片的初始位置,它通常是以x與y坐標(biāo)定位的,所以通常都取兩個(gè)值,默認(rèn)值是0% 0%。

    它按照水平、垂直方式,部署了8個(gè)屬性值:

  •     水平:left、center、right;
  •     垂直:top、center、bottom;
  •     垂直與水平綜合:x-% y-%、x-pos y-pos。

    前6個(gè)屬性值都很簡(jiǎn)單,最后兩個(gè)屬性值乍一看會(huì)有些摸不到頭腦。x-% y-%的意思是x軸的百分?jǐn)?shù)和y軸的百分?jǐn)?shù),x-pos y-pos的意思是x軸的值和y軸的取值。

示例:


  p {

    background-image:url(../images/background.jpg);

    background-position:20px -30px;

    background-repeat:no-repeat;

    }

    div   {

background-image:url(../images/background.jpg);

    background-position:50% 20%;

    background-repeat:no-repeat;

    }


背景附著屬性(background-attachment)


    這個(gè)屬性依然要跟隨background-image后面使用,它決定背景圖片是跟隨內(nèi)容滾動(dòng),還是固定不動(dòng),它有兩個(gè)屬性值:

  •     scroll(默認(rèn)值,背景圖片跟隨內(nèi)容滾動(dòng)。)
  •     fixed(背景圖片固定,不跟隨內(nèi)容滾動(dòng)。)


示例:


.para6   {

background-image:url(../images/background.jpg);

background-position:50% 20% ;

background-repeat:no-repeat;

background-attachment:fixed;

}


背景屬性(background)


    和前幾篇文章中提到的font屬性使用方法一樣,background也是綜合縮寫,書寫順序:


  background:background-color background-image background-repeat background-attachment background-position;


示例:

.para7   {

background:#000000 url(../images/background.jpg);


}

.para8   {

background:url(../images/background.jpg) repeat fixed left top;

}


    在網(wǎng)頁的實(shí)際制作過程中,還需要注意網(wǎng)頁的背景顏色和背景圖片設(shè)置的許多細(xì)節(jié)問題,需要在實(shí)際應(yīng)用中細(xì)心體會(huì)和鉆研,以后我們?cè)俾治觥?

相關(guān)文章

最新評(píng)論