2017-02-24 91 views
-1

我可以顯示選定的鏈接,但是當我在頁面中單擊某處時,高亮消失。我也在努力讓懸停的邊緣突出顯示。如何使選定的鏈接處於活動狀態

我附上了一段代碼和圖片供參考。

enter image description here

#sidebarContent a :ACTIVE, #sidebarContent a:FOCUS{ 
     background-color: Green; 
     padding: 5px 10px; 
     /* margin-left:auto; 
     margin-right:auto; */ 
     text-decoration: none; 
     width: 120px;   
    } 
+0

你必須一類附加到的鏈接; ':focus'和':active'只要與該元素交互(如':hover'),就會一直存在。 – gyre

+0

正如我看到這是用jQuery標記,我會建議你去這個:http://stackoverflow.com/questions/7738219/how-to-keep-active-css-style-after-clicking-an-元件。當涉及到邊緣的突出部分時,我認爲我們可能需要一些細節 – Coss

+0

完美。謝謝Gents! –

回答

2

如果您使用的角度應用程序(你加入這個標籤) - 您可以使用active類標記,而不是使用::focus僞類您當前的路線。

<a href="#/home" ng-class="{active: isActive('home')}">Home</a> 
    <a href="#/about" ng-class="{active: isActive('about')}">About</a> 

其中:

$scope.isActive = function(path) { 
    return $location.path() == '/' + path; 
} 

請檢查此琴https://jsfiddle.net/vadimb/2waujx3m/

+0

如果他真的在使用'angular-ui-bootstrap',那麼這就是更好的例子。 BTW +1 jsfiddle鏈接 –