css中背景相關的屬性是哪些?css背景屬性的介紹

來源:互聯網
上載者:User

css背景有哪些相關屬性?下面本篇文章給大家帶來關於css背景屬性的介紹,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

1、css背景屬性之為內容設定背景色:background-color;
屬性:
顏色;
inherit;繼承父級樣式

box.html

<!doctype html><html><head>    <mate charset="utf-8">    <title>背景</title>    <link href="box.css" type="text/css" rel="stylesheet">    </head>    <body>    <p為內容設定背景色:background-color;</p>    </body>    </html>

box.css

body{    background-color:#123456;}

2、css背景屬性之為內容設定背景為圖片background-image:url();
box.css

body{    background-color:#123456;        background-image:url(image.png);    }

3、css背景屬性之固定背景圖片background-attachment
(在CSS中使用 background-attachment屬性可以將圖片固定在瀏覽器上,如果拖動捲軸,背景圖片不會隨著網頁內容的滾動而滾動,像文字浮在圖片上)
屬性值:
scroll;背景圖片隨內容滾動,預設值
fixed; 背景圖片固定,不隨內容滾動
inherit;繼承父類樣式

box.css

body{    background-color:#123456;        background-image:url(image.png);        background-attachment:fixed;        font-size: 45px;    }

4、css背景屬性之背景圖片平鋪background-repeat;
屬性值:
repeat;平鋪背景圖片;預設
no-repeat;不平鋪圖片;
repeat-x;在水平方向平鋪
repert-y;在豎直方向平鋪

box.css

 body{     background-color:#123456;         background-image:url(image.png);         background-attachment:fixed;         font-size: 45px;         background-repeat: repeat-y;    }

5、css背景屬性之背景圖片定位background-position
屬性值:
top;頂部
center;中間
bottom;底部
right;右邊
left;左邊
inherit;繼承父類樣式
樣式:
xxxpx,xxxpx;
xxx%,xxx%;
xxxpx,top;

box.css

body{    background-color:#123456;        background-image:url(image.png);        background-attachment:fixed;        font-size: 45px;        background-repeat:no-repeat;        background-position:left;    }
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.