2011-08-02 54 views
1

有沒有任何CSS屬性來獲得鏈接時點擊鏈接(不使用javascript/jquery)?CSS屬性來獲取點擊的url

+3

要*獲得*網址?點擊鏈接時你希望得到什麼結果? – tw16

+0

你不能得到的URL。但你可以知道,目標是什麼。 ':target' – meo

+0

我需要在html郵件中添加css屬性來跟蹤用戶是否點擊了URL,並在HTML郵件中點擊了哪一個 – joe

回答

3

:target-pseudo-class,它匹配實際點擊的錨定目標,在#之後的URL中給出。

例如調用index.php#paragraph1會在你的CSS使用類似匹配

<p id="paragraph1">…</p> 

:target { background: #fc0; } 

爲了得到一些高亮喜歡這裏的SO,使用類似:

[id] { 
    -webkit-transition: background-color 2s ease; 
    -moz-transition: background-color 2s ease; 
    -o-transition: background-color 2s ease; 
    transition: background-color 2s ease; } 
[id]:target { 
    background-color: #ffa; 
    color: #6a0504; } 

要在點擊時顯示錨點的網址,請使用:

a[href]:active::after { 
    content: ' (' attr(href) ')'; 
    /* more stylings */ 
}