標籤:set second 並集 20px 步驟 content 12px class選取器 line
1.css的文法
a.位置
<head>
<style type="text/css"> //css代碼
</style>
</head>
b.文法
選取器{
屬性名稱1:屬性值1;
屬性名稱2:屬性值2;
}
例:h1{
font-size:12px; //字型大小
color:red; //字型顏色
}
注意:多個用屬性用分號分隔
2.選取器
a.標籤選取器
文法:
標籤名{
------
}
b.類別選取器
文法:
.class屬性值{
-------
}
步驟:
第一步:給指定的html標籤加上class屬性
第二步:在style中寫
.class屬性值{
-------
}
| |
|
.green{ font-size:20px; color:green; } |
|
c.id選取器
文法:
#id屬性值{
......
}
步驟:
第一步:給指定的html標籤加上id屬性
第二步:在style中寫
#id屬性值{
-------
}
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>標籤選取器的用法</title> <style type="text/css"> #first{font-size:16px;} #second{font-size:24px;} </style> </head> <body> <h1>北京歡迎您</h1> <p id="first">北京歡迎您,有夢想誰都了不起!</p> <p id="second">有勇氣就會有奇蹟。</p> <p>北京歡迎您,為你開天闢地</p> <p>流動中的魅力充滿朝氣。</p> </body> </html> |
| |
3.引用樣式的方式
a.行內樣式
使用style屬性引入樣式
列:<h1 style="font-sze:16px;color:red;">xxx</h1>
b.內部樣式
在head中寫style
列:h1{xxxx}
c.外部樣式
把CSS代碼儲存在以CSS結尾的檔案(層疊樣式檔案)
把CSS檔案引入html中
引入方式兩種:
第一種:連結方式
<link rel="stylesheet" href="檔案路徑" type="text/css"/>
第二種:匯入方式
<style>
@import url("檔案路徑")
</style>
4.優先順序
行內樣式>內部樣式>外部樣式(就近原則)
id選取器>class選取器>標籤選取器
5.進階選取器
a.後代選取器
父標籤 子標籤{
......
}
| |
|
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>後代選取器</title> <style type="text/css"> h3 strong{color:blue;font-size:36px;} strong{color:red; font-size:16px;} </style> </head> <body> <strong>問君能有幾多愁,</strong> <h3>恰似一江<strong>春水</strong>向東流.</h3> </body> </html> |
|
b.交集選取器
選取器(class選取器或者id選取器){
......
}
| |
|
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>交集選取器</title> <style type="text/css"> p .txt{color:red;} p.txt{color:blue;line-height:28px;} </style> </head> <body> <h2>蝶戀花•庭院深深深幾許</h2> <p class="txt">庭院深深深幾許,楊柳堆煙,簾幕無重數。玉勒雕鞍遊治處,樓高不見章台路。<br/> <strong class="txt">雨橫風狂三月幕,門俺黃昏,無計留春住。</strong>淚眼問花花不語,任紅飛過鞦韆去。</p> </body> </html> |
|
c.並集選取器
選取器1,選取器2,選取器3,......選取器n{
......
}
| |
|
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>並集選取器</title> <style type="text/css"> h3,.first,.second,#end{font-size:16px;color:green;font-weight:normal;} </style> </head> <body> <h2>蝶戀花•庭院深深深幾許</h2> <h3>庭院深深深幾許,楊柳堆煙,簾幕無重數。</h3> <p class="first">玉勒雕鞍遊治處,樓高不見章台路。</p> <p class="second">雨橫風狂三月幕,門俺黃昏,無計留春住。</p> <p id="end">淚眼問花花不語,任紅飛過鞦韆去。</p> </body> </html> |
|
初識CSS