2011-10-20 40 views
0

HTML:風格<a>鏈接一次不同風格

<div id="content"> 
<p> some text </p> 
<a href="#"> some link aaa </a> 
<a href="#"> some other link bbb</a> 
</div> 

CSS:

#content a 
{ 
color: #red; 
text-decoration: underline; 
} 

.blue { color: #blue; } 

我喜歡的風格 「其他一些鏈接BBB」 與CSS。但我喜歡其他鏈接是不同的顏色。我嘗試添加類,但沒有運氣..它覆蓋了一個

我應該怎麼做?

爲什麼?

回答

0
<div id="content"> 
<p> some text </p> 
<a href="#" class="f"> some link aaa </a> 
<a href="#" class="f2"> some other link bbb</a> 
</div> 

#content a.f 
    { 
    color: red; 
    text-decoration: underline; 
    } 

    #content a.f2 
    { 
    color: black; 
    text-decoration: underline; 
    } 
+0

對無關和無意義的課堂進行倒票。 –

1

變化

.blue { color: blue; } 

#content a.blue { color: blue; } 

編輯:編號是防止它。該ID優先。
此外,#無效。

+0

爲什麼你告訴我:#無效。 ? – menardmam

+0

我認爲他指的是你的href佔位符。 lol –

+0

第二次看,他指的是你的CSS顏色之前的#。哈希標記僅在顏色十六進制值之前使用,而不是顏色名稱。 –

2

這是一個特殊問題。嘗試更改.blue#content a.blue

2

您在那裏遇到了CSS特殊問題。 HTML狗有這個a good tutorial

從文章:

一組嵌套的選擇器的實際特異性需要一些 計算。基本上,你給每個id選擇器(「#whatever」)一個 的值爲100,每個類選擇器(「.whatever」)的值爲10和 每個HTML選擇器(「無論」)的值爲1。他們全部 起來,嘿presto,你有特殊的價值。

+1

WOW,HTML Dog將其清晰地表現爲水!每個網頁設計師/程序員都應該在寫作CSS之前明白!謝謝x1000 – menardmam

+0

lol np。很高興我能幫上忙。 =) –