2012-04-10 76 views
0

我有以下html文本。更改鏈接的屬性

<ol class="otherstufflinks"> 
    <li> 
     <a href="./pythonNotes/index.html">Python notes</a> 
    </li> 
    <li> 
     <a href="./figure.html">Cool figure made using</a> 
     <a href="http://mbostock.github.com/d3/" class="nestedlink">d3.js library.</a> 
    </li>    
</ol> 

css文件中的相關部分:

a:link, a:visited { 
    color: steelblue; 
    text-decoration: none; 
} 

a:hover { 
    color: rgb(210,135,60); 
} 

.otherstufflinks > li, 
.otherstufflinks a:link, .otherstufflinks a:visited 
{ 
    font-weight: normal; 
    color: rgb(75,75,75); 
} 

.otherstufflinks a:hover { 
    color: rgb(210,135,60) 
} 

我要選擇不同的顏色,紅說,爲與類nestedlink的鏈接。如果有人能告訴我該怎麼做會很感激?我嘗試了以下,但沒有一個工作。

首先嚐試:

.nestedlink a:link, .nestedlink a:visited { 
    color: red; 
} 

第二個嘗試:

.otherstufflinks .nestedlink a:link, .otherstufflinks .nestedlink a:visited { 
     color: red; 
    } 

我沒有看到,我錯了。謝謝你的幫助。

回答

5
a.nestedink:link, a.nestedlink:visited { 
color: red; 
} 

我相信與一個和唯一使用.nestedlink,默認a:link屬性將覆蓋.nestedlink。

+0

謝謝傑克和卡薩波。但是,爲什麼它在'.otherstufflinks a:link'的情況下起作用。順便說一句你的答案效果很好。謝謝。所以說我必須等7分鐘才能接受它。 – Curious2learn 2012-04-10 20:21:35

2

試試看

a.nestedlink:visited, a.nestedlink:visited { 
    color: red; 
} 

肯定?

+0

這不足以覆蓋其他選擇器。 – BoltClock 2012-04-10 20:19:25

+0

這沒有奏效。 – Curious2learn 2012-04-10 20:20:53

1

你的CSS是壞,嘗試:

a.nestedlink { color: red; } 

這意味着 「適用於帶班nestedLink 'A' 型(錨)的元素」。你有什麼意思「適用於任何具有類嵌套鏈接元素的後代的錨點」

+0

這沒有奏效。顏色沒有變成紅色。 – Curious2learn 2012-04-10 20:22:41

+0

這個作品除了Link是大寫的,不應該是... – 2012-04-10 20:24:02

+0

不,我沒有複製和粘貼。我正確輸入了'nestedlink'。它仍然沒有工作。 – Curious2learn 2012-04-10 20:27:15