首頁  >  文章  >  web前端  >  css怎麼放圖片

css怎麼放圖片

藏色散人
藏色散人原創
2021-04-25 10:07:2646501瀏覽

css放圖片的方法:1、使用background簡寫屬性在設定背景時引入圖片;2、直接使用background-image屬性引入背景圖片。

css怎麼放圖片

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

css怎麼放圖片?

隨著網路的發展,網路速度不斷提升,我們現在的網頁也變的更加豐富起來,除了能夠傳輸文字外,我們還可以傳輸圖片。我們該如何使用css在網頁中放置圖片?下面我們兩個來看看使用css在網頁中放圖片的方法。

css可以使用background簡寫屬性在設定背景時引入圖片,也可以使用background-image屬性來引入背景圖片。 background-image屬性為元素設定背景影像。

使用background簡寫屬性引入圖片:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<style>
body
{ 
background: #00ff00 url(&#39;img/3.jpg&#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>
</body>
</html>

效果圖:

css怎麼放圖片

#使用background-image屬性在網頁中放入圖片:

<html>
<head>
<style type="text/css">
body {background-image:url(/i/eg_bg_04.gif);}
</style>
</head>
<body></body>
</html>

效果圖:

css怎麼放圖片

background 簡寫屬性:

background 簡寫屬性在一個宣告中設定所有的背景屬性。

可以設定以下屬性:

background-color
background-position
background-size
background-repeat
background-origin
background-clip
background-attachment
background-image

如果不設定其中的某個值,也不會出問題,例如background:#ff0000 url('smiley.gif'); 也是允許的。

通常建議使用這個屬性,而不是分別使用單一屬性,因為這個屬性在較老的瀏覽器中能夠得到更好的支持,而且需要鍵入的字母也更少。

background-image 屬性:

background-image 屬性為元素設定背景圖片。

元素的背景佔據了元素的全部尺寸,包括內邊距和邊框,但不包括外邊距。

預設地,背景圖像位於元素的左上角,並在水平和垂直方向上重複。

提示:請設定一個可用的背景顏色,這樣的話,如果背景圖片不可用,頁面也可獲得良好的視覺效果。

屬性值:

url('URL') 指向影像的路徑。

none 預設值。不顯示背景影像。

inherit 規定應該從父元素繼承 background-image 屬性的設定。

【推薦學習:css影片教學

#

以上是css怎麼放圖片的詳細內容。更多資訊請關注PHP中文網其他相關文章!

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