1.css背景
1)背景色
有外延的文字背景色:
p{background-color:blue;padding:10px;}
p{background-color:#0000ff}
p{background-color:rgb{0,0,255}
background-color不能繼承,默認(rèn)值transparent,意思是透明。
2)背景圖片
可以給body、段落等設(shè)置背景圖片
body{background-image:url(i/test.gif);}本地路徑?
p.test{background-image:url(j/test.gif)}
<p class=“test”>這個(gè)段落的背景圖片是test中定義的顏色<p>
3)背景圖片重復(fù)
可以在水平、垂直對(duì)背景圖片進(jìn)行重復(fù)。
水平:repeat-x
垂直:repeat-y
不平鋪:no-repeat
body{
background-image:url(i/test.gif);
background-repeat:repeat-x;
}
不寫重復(fù)的會(huì)默認(rèn)水平垂直都平鋪
4)背景圖片定位
使用關(guān)鍵詞top,left,right,bottom,center,關(guān)鍵詞可以成對(duì)出現(xiàn),也可以只出現(xiàn)一個(gè),另外一個(gè)默認(rèn)是center
body{
background-image:url(i/test.gif);
background-position:center right;
}
使用百分?jǐn)?shù)值定位,第一個(gè)代表垂直方向,第二個(gè)代表水平方向,如果只出現(xiàn)一個(gè),這個(gè)值代表水平值。
body{
background-image:url(i/test.gif);
background-position:10% 90%;
}
使用像素值定位,第一個(gè)代表距離上方的距離,第二個(gè)代表距離左邊的距離。
body{
background-image:url(i/test.gif);
background-position:10px 80px;
}
5)背景圖片固定
可以時(shí)背景圖片不隨著頁(yè)面滾動(dòng)
body{
background-image:url(i/test.gif);
background-position:center right;
background-attachment:fixed
}
2.css文本
1)文本縮進(jìn)
不能應(yīng)用到行內(nèi)元素。
p{text-indent:2em;}
可以使用負(fù)值,但是為了前面的文字避免超出瀏覽器,可以使用padding
p{text-indent:4em;padding-left:5em;}
2)水平對(duì)齊方式
它會(huì)影響一個(gè)元素中的文本行互相之間的對(duì)齊方式
左對(duì)齊:
p{text-align:left;}
右對(duì)齊:
p{text-align:right;}
居中對(duì)齊:
p{text-align:center;}
3)字間隔
增加單詞間距:
p{word-spacing:10px;}
減少單詞間距:
p{word-spacing:-0.2px;}
4)字母間距
增加單詞間距:
p{letter-spacing:10px;}
減少單詞間距:
p{letter-spacing:-0.2px;}
5)處理文本大小寫
默認(rèn)不做任何改動(dòng)
小寫變?yōu)榇髮懀?br>
h1 {text-transform: uppercase}
大寫變?yōu)樾懀?br>
h1 {text-transform: lowercase}
首字母變大寫:
h1 {text-transform:capitalize}
6)文本裝飾
不裝飾、關(guān)閉文本裝飾:
a {text-decoration: none;}
文本下劃線裝飾:
a {text-decoration: underline;}
文本上劃線裝飾:
a {text-decoration: overline;}
文本中間貫穿線:
a {text-decoration: line-through;}
本文閃爍:
a {text-decoration: blink;} 但是這個(gè)我試了沒有生效
3)css字體
字體:font-family 包括通用字體系列和指定字體系列
大小:font-size
h1 {font-size:60px;}
或者
h1 {font-size:1.5em;}瀏覽器中默認(rèn)的文本大小是 16 像素。因此 1em 的默認(rèn)尺寸是 16 像素。
樣式:font-style:normal、italic、oblique
粗細(xì):font-weight:blod、100~900
4)鏈接:
a:link {text-decoration:none;} /* 未被訪問(wèn)的鏈接 /
a:visited {text-decoration:none;color:gray} / 已被訪問(wèn)的鏈接 /
a:hover {text-decoration:underline;color:blue} / 鼠標(biāo)指針移動(dòng)到鏈接上 /
a:active {text-decoration:underline;} / 正在被點(diǎn)擊的鏈接 */
active必須位于hover之后
hover必須位于link和visited之后
5)列表
<style type="text/css">
ul.circle {list-style-type: circle}
ul.square {list-style-type: square}
ul.none {list-style-type: none}
ul.disc{list-style-type:disc}
</style>
<ul class="disc">
<li>水</li>
<li>咖啡</li>
</ul>
圖片作為列表項(xiàng)圖標(biāo):
ul
{
list-style-image: url('/i/eg_arrow.gif')
}
鏈接:http://www.w3school.com.cn/css/css_background.asp