首頁  >  文章  >  web前端  >  background-image屬性怎麼用

background-image屬性怎麼用

青灯夜游
青灯夜游原創
2019-02-18 11:48:3024509瀏覽

background-image屬性是用來設定元素的一個或多個背景圖像,用逗號(,)分隔。

background-image屬性怎麼用

CSS  background-image屬性

##作用:background-image屬性為元素設定背景圖像。

語法:

background-image:url(图片路径)

說明:background-image屬性設定的背景圖片會佔據了元素的全部尺寸,包括內邊距和邊框,但不包括外邊距。預設地,背景圖像位於元素的左上角,並在水平和垂直方向上重複。

提示:請設定一個可用的背景顏色,這樣的話,如果背景圖片不可用,可以使用背景色帶代替。

CSS  background-image屬性的使用範例#

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 

<style>
#example1 {
    background-color:#cccccc;
    background-image:url("https://img.php.cn/upload/article/000/000/024/5c6a290265dba776.gif"),url("https://img.php.cn/upload/article/000/000/024/5c6a2793a13ac244.gif");
    background-position: right bottom, left top;
    background-repeat: no-repeat, repeat;
    padding: 15px;
}
</style>
</head>
<body>

<div id="example1">
<h1>Hello World!</h1>
<p>测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!</p>
<p>测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!</p>
</div>

</body>
</html>

效果圖:

background-image屬性怎麼用

#以上就是本篇文章的全部內容,希望能對大家的學習有所幫助。


以上是background-image屬性怎麼用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn