2015-06-20 54 views
1

我知道這個問題已經在這裏問過,我已經做了一些Google搜索,看看我能否得到它的工作,但我發現的解決方案根本不適合我。 這裏是我的代碼CSS a:活動僞類不工作

<div id="rightbar" class="float-r"> 
     <table width="100%" cellpadding="0" cellspacing="0"> 
     <tbody><tr> 
      <td colspan="2"><a class="block active" href="dashboard.php">My Dashboard</a></td> 
     </tr>   
     <tr> 
      <td><a class="block" href="profile.php">My Profile</a></td>    
     </tr>   
     <tr> 
      <td><a class="block" href="edit_profile.php">Edit Personal Details Form</a></td>     
     </tr> 
     <tr> 
      <td><a class="block" href="edit_form.php">Edit Members Form</a></td>     
     </tr> 
     <tr> 
      <td colspan="2" class="last-child"><a style="border-bottom:solid 1px #eaeaea;width:235px;" class="block" href="logout.php">Log Out</a></td>    
     </tr> 
     </tbody></table> 
    </div> 

.float-r { 
float: right; 
} 

#rightbar { 
background: #ffffff; 
float: right; 
width: 250px; 
margin-top: 10px; 
height: 530px; 
margin-right: 10px; 
border-bottom: solid 1px #c8c9c9; 
} 

#rightbar a { 
width:235px; 
color: #000; 
font-size:14px; 
text-decoration:none; 
} 

#rightbar a:hover{ 
background-color:#efefef; 
width:235px; 
} 

#rightbar a:active{ 
background-color:#eaeaea; 
width:235px; 
} 

我想,當我點擊一個鏈接,懸停在了它的一個背景:主動要改變,如果你滾動,你會看到這樣問題的選項頂部就拿#1這裏,標籤,用戶,徽章,如果我點擊每個鏈接的背景更改爲橙色。我想要那樣的東西。謝謝。

+0

你在用什麼切換主動? – ajmajmajma

+0

一切似乎都奏效。你認爲什麼不按預期工作? – nicael

+0

您是否嘗試過#rightbar table tbody tr td a:hover { background-color:#efefef; width:235px; } –

回答

2

你的代碼工作正常。你可以看到這裏,當我把它切換成紅色,當你按住鼠標點擊它的正常工作。

https://jsfiddle.net/zk3sw43m/2/

不僅改變了這裏的紅色爲清楚起見

#rightbar a:active{ 
background-color:red; 
width:235px; 
} 
+0

看到我的意思是當我點擊鏈接並將鼠標懸停在外,我希望它仍然保持紅色,請在此處選擇實例Stackoverflow如果您滾動到頂部,您將看到類似問題的選項,標籤,用戶,徽章,如果我點擊每個鏈接的背景更改爲橙色。我想要那樣的東西 –

+0

@Rhyno_xD是一個完全不同於css:active的功能。您可能想嘗試將某個類交換到該項目並更改CSS。例如,堆棧溢出使用類「youarehere」風格,就像你在那裏說的那樣。 CSS:活躍就在您處於點擊該項目的狀態。看到這裏參考 - http://www.w3schools.com/cssref/sel_active.asp – ajmajmajma

+0

我明白你的意思,它現在的工作,但我使用PHP包括添加頭到頁面將有點問題這樣做,但我會想到一些事情。非常感謝。 –