3.5 Selectors - class 和 id
範例 1
<h1 class="title1">這是內文標題</h1>
<p id="the_para">這是段落</p>/* . 符號表示 class 的名稱 */
.title1{
color: blue;
}
/* # 符號表示 id 的名稱 */
#the_para{
color: red;
}<h1 class="title1">這是內文標題</h1>
<p id="the_para">這是段落</p>/* . 符號表示 class 的名稱 */
.title1{
color: blue;
}
/* # 符號表示 id 的名稱 */
#the_para{
color: red;
}<h1 class="title1 change_size">這是內文標題</h1>.title1{
color: blue;
}
.change_size{
/* 文字大小設定成 20px */
font-size: 20px;
}<h1 class="title1">這是h1內文標題</h1>
<h2 id="title2">這是h2內文標題</h2>h1.title1{
color: red;
}
h2#title2{
color: blue;
}<h1 class="title1">這是h1內文標題</h1>
<h1 class="title1 other_style">這是h1內文標題</h1>h1.title1{
color: red;
}
/* h1 元素有 title1 樣式,同時也有 other_style 樣式,則會套用 */
h1.title1.other_style{
border: 1px solid red;
}