style="style_definition"
<h1 style="color:blue; text-align:center">This is a header</h1>
<p style="color:red">This is a paragraph.</p>
複製代碼
style_definition
一個或多個由分號分隔的 CSS
屬性和值。<style>
標籤<html>
<head>
<style type="text/css">
span {color:red}
p {color:blue}
</style>
</head>
<body>
<span>span</span>
<div>div</div>
</body>
</html>
複製代碼
<style>
標籤用於爲 HTML
文檔定義樣式信息。style
中,您能夠規定在瀏覽器中如何呈現 HTML 文檔。type
屬性是必需的,定義 style
元素的內容。惟一可能的值是 "text/css"
。style
元素位於 head
部分中。<style type="text/css"
>"text/css"
。<link rel="stylesheet" type="text/css" href="theme.css">
複製代碼
stylesheet
文檔的外部樣式表。<link href="URL">
id
選擇器class
選擇器*
通用選擇器設置元素的背景顏色。css
body{
background-color:yellow;
}
複製代碼
color_name
規定顏色值爲顏色名稱的背景顏色(好比 red
)。hex_number
規定顏色值爲十六進制值的背景顏色(好比 #ff0000
)。rgb_number
規定顏色值爲 rgb 代碼的背景顏色(好比 rgb(255,0,0)
)。transparent
默認。背景顏色爲透明。設置背景圖像
元素的背景佔據了元素的所有尺寸,包括內邊距和邊框,但不包括外邊距。
默認地,背景圖像位於元素的左上角,並在水平和垂直方向上重複。 html
body {
background-image: url(bgimage.gif);
background-color: #000000;
}
複製代碼
url('URL')
指向圖像的路徑。none
默認值。不顯示背景圖像。設置是否及如何重複背景圖像。瀏覽器
body {
background-image: url(stars.gif);
background-repeat: repeat-y;
}
複製代碼
repeat
默認。背景圖像將在垂直方向和水平方向重複。repeat-x
背景圖像將在水平方向重複。repeat-y
背景圖像將在垂直方向重複。no-repeat
背景圖像將僅顯示一次。設置背景圖像的開始位置。url
body{
background-image:url('bgimage.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
複製代碼
top center right
若是您僅規定了一個關鍵詞,那麼第二個值將是"center"
。 默認值:0% 0%。x% y%
第一個值是水平位置,第二個值是垂直位置。左上角是 0% 0%
。右下角是 100% 100%。 若是您僅規定了一個值,另外一個值將是 50%。xpos ypos
第一個值是水平位置,第二個值是垂直位置。 左上角是 0 0
。單位是像素 (0px 0px)
或任何其餘的 CSS
單位。 若是您僅規定了一個值,另外一個值將是50%
。%
和 position
值。設置背景圖像是否固定或者隨着頁面的其他部分滾動。spa
body {
background-image: url(bgimage.gif);
background-attachment: fixed;
}
複製代碼
scroll
默認值。背景圖像會隨着頁面其他部分的滾動而移動。fixed
當頁面的其他部分滾動時,背景圖像不會移動。在一個聲明中設置全部的背景屬性。
一般建議使用這個屬性,而不是分別使用單個屬性,由於這個屬性在較老的瀏覽器中可以獲得更好的支持,並且須要鍵入的字母也更少。code
body {
background: #00FF00 url(bgimage.gif) no-repeat fixed top;
}
複製代碼