CSS的構成與規則

CSS(Cascading Style Sheets) 使用方式如下

1
選取器 { 屬性 :  值;}

說明

  1. 選取器 : 使用在html 中的地方,ex : class 、 id 、object
  2. 屬性 : 設定哪個屬性,ex: 背景、大小、寬度
  3. 值 : 設定什麼值,ex : #ddd , px,1s

選取器

  1. Class 選取器
1
2
3
.title{
background: yellow;
}
  1. ID 選取器
1
2
3
#title{
background: yellow;
}
  1. 後代選取器
1
2
3
.list1 li{
list-style: decimal;
}
  1. 屬性選取器
1
2
3
.img-resp[alt]{
border-color:#000;
}
  1. 擬態選取器
1
2
3
a:hover{
color: #000;
}