!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns= http://www.w3.org/1999/xhtml head meta http-equiv= Content-Type content= text/html; charset=gb2312 / title Id /title style type= text/css !-- #STYLE_1 { font-size: 20px; } -- /style /head body div id= STYLE_1 用Id來給對(duì)象應(yīng)用樣式 /div /body /html
2:使用.定義樣式,并使用class為對(duì)象應(yīng)用樣式。
例:
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns= http://www.w3.org/1999/xhtml head meta http-equiv= Content-Type content= text/html; charset=gb2312 / title Id /title style type= text/css !-- .STYLE_1 { font-size: 20px; } -- /style /head body div >3:不定義樣式,直接使用style為對(duì)象應(yīng)用樣式。
例:!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns= http://www.w3.org/1999/xhtml head meta http-equiv= Content-Type content= text/html; charset=gb2312 / title Id /title /head body div >使用這三種方法所產(chǎn)生的效果是相同的,但我們需要注意的是,這三種方法間的優(yōu)先級(jí)問題。
如果我們對(duì)一個(gè)對(duì)象同時(shí)使用上述三種方法定義樣式,會(huì)怎么樣呢?
比如我們先定義一個(gè)#STYLE { font-size:12px; }再定義一個(gè).STYLE { font-size:14px; }最后在對(duì)象上使用 >!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns= http://www.w3.org/1999/xhtml head meta http-equiv= Content-Type content= text/html; charset=gb2312 / title Id /title style type= text/css !-- #STYLE { font-size: 12px; } .STYLE { font-size: 14px; } -- /style /head body div id= STYLE >這種情況下,瀏覽器會(huì)根據(jù)三種方式的優(yōu)先級(jí),即style id class來為對(duì)象應(yīng)用樣式。上述例子中,div中的文字會(huì)顯示為16px大小。
以上就是css中的id,class,style三種應(yīng)用樣式用法詳解的詳細(xì)內(nèi)容,html教程
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答