1,背景樣式
1-1,背景顏色
body { background-color: #0f0 }
運行效果:
背景顏色還有一下幾種寫法:
1, background-color: yellow
2, background-color: rgb(250,0,255)
1-2, 背景圖片
body { background-image: url(../img/bgimage.gif) }
運行效果:
背景圖不僅僅運用于body,還可以運用于段落和行內元素
1-3,背景圖重復
body {
? background-image: url(../img/bgimage.gif);
? background-repeat: no-repeat ? /*不重復*/
}
運行效果:
背景重復的用法:
background-repeat: repeat-x ?/*水平重復*/
background-repeat: repeat-y ? /*垂直重復*/
垂直重復的效果圖:
1-4,背景關聯
body {
? background-image: url(../img/bgimage.gif);
? background-repeat: no-repeat;
? background-attachment: fixed
}
運行效果:
聲明圖像相對于可視區是固定的(fixed),因此不會受到滾動的影響。默認值是 scroll(滾動),背景會隨文檔滾動。
1-5,背景圖定位
1】關鍵字
body {
? background-image: url(../img/bgimage.gif);
? background-repeat: no-repeat;
background-attachment: fixed;
? background-position: top
}
運行效果:
background-position:的關鍵字有:top、bottom、left、right 和 center。關鍵字可以按任何順序出現,但要保證關鍵字不超過兩個 (一個對應水平方向,另一個對應垂直方向)。如果只出現一個關鍵字,則認為另一個關鍵字是 center。
2】百分數值
body {
? background-image: url(../img/bgimage.gif);
? background-repeat: no-repeat;
? background-attachment: fixed;
? background-position: 30% 60%
}
運行效果:
圖像中描述為 30% 60% 的點(中心點)與元素中描述為 30% 60% 的點(中心點)對齊。
3】長度值
長度值解釋的是元素內邊距區左上角的偏移。偏移點是圖像的左上角。比如,如果設置值為 200px 50px,圖像的左上角將在元素內邊距區左上角向右 200 像素、向下 50 像素的位置上:
body {
? background-image: url(../img/bgimage.gif);
? background-repeat: no-repeat;
? background-attachment: fixed;
? background-position: 200px 50px
}
運行效果:
2,文本樣式
通過文本屬性,可以改變文本的顏色、字符間距,對齊文本,裝飾文本,對文本進行縮進等等。
2-1,縮進
p { text-indent: 2em }
運行效果:
text-indent: 的值可以是長度值,百分比值,em
2-2,文本對齊
h1 { text-indent: center }
運行效果:
text-align: 值 left、right 和 center 會導致元素中的文本分別左對齊、右對齊和居中,justify 在兩端對齊文本中,文本行的左右兩端都放在父元素的內邊界上
2-3,間隔
1】字和字母間隔
p {
? text-indent: 6em;
? letter-spacing: 2em
}
運行效果:
2】單詞間距
p { word-spacing: 20px }
運行效果:
2-3,文本裝飾
p { text-decoration: line-through }/*貫穿線*/
運行效果:
text-decoration: 的值有 none/*無*/ ?underline/*下面劃線*/ ?overline/*上面劃線*/ ?line-through/*貫穿線*/
text-decoration的值在一個元素中有多個時,會被替換而不會累積
2-4,處理空白符
<p>雨? 仍舊繼續下著? ? ? ? ? ? 但卻不像剛才那么單調? 開始有了變化
它時而大? 時而小? 時而急? 時而緩。</p>
p { white-space: pre }
運行效果:
white-space: 的值:
normal 合并空白符和換行符 ?并自動換行
nowrap 合并空白符和換行符 ?且不自動換行
pre 保留空白符,換行符,但不自動換行
pre-wrap ?保留空白符和換行符 并自動換行
pre-line ?合并空白符 ?保留換行符 并自動換行