首頁  >  文章  >  web前端  >  如何為html設定背景

如何為html設定背景

青灯夜游
青灯夜游原創
2021-07-01 14:17:5762496瀏覽

html設定背景的方法:1、使用body標籤的bgcolor屬性設定背景顏色;2、使用body標籤的background屬性設定背景圖片;3、在body標籤中使用style屬性,新增「background:顏色值/url('圖片路徑')」。

如何為html設定背景

本教學操作環境:windows7系統、CSS3&&HTML5版、Dell G3電腦。

html設定背景

1、body標籤的bgcolor屬性

bgcolor 屬性規定文檔的背景顏色。

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
</head>
<body bgcolor="#E6E6FA">
<h1>Hello world!</h1>
</body>
</html>

效果圖:

如何為html設定背景

注意:如果使用顏色名,則不同瀏覽器的渲染結構不一樣,如果使用RGB程式碼,火狐瀏覽器無法顯示正確顏色。

提示: 如果所有瀏覽器要顯示相同顏色,請使用十六進位的顏色代碼。

2、body標籤的background屬性

background 屬性規定規定文件的背景影像。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body background="demo/img/1.jpg">
</body>
</html>

效果圖:

如何為html設定背景

#3、css background 屬性

background屬性是一個簡寫屬性,可以在一個聲明中設定所有的背景屬性。

可以設定的屬性分別是:

  • background-color

  • background-position

  • background-size

  • background-repeat

  • background-origin

  • background-clip

  • background-attachment

  • #background-image

##範例:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style>
body
{ 
background: pink url(&#39;smiley.gif&#39;) no-repeat fixed center; 
}
</style>
</head>

<body>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
</body>

</html>

效果圖:


如何為html設定背景

推薦教學:《

html影片教學

以上是如何為html設定背景的詳細內容。更多資訊請關注PHP中文網其他相關文章!

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