Reputation: 3920
I have a navbar with dropdown menus using Bootstrap. I created a border around the dropdown list item to make it look as if it's a tab. The border is only there on focus. The user clicks the tab to toggle it closed but the border still shows there as it's still in focus. How can I remove the focus after click?
Here's the CSS
#refine2 .dropdown-toggle:active {background-color:transparent; border:0;} #refine2 .dropdown-toggle:focus {border-top: 1px solid #e3e3e3; border-right: 1px solid #e3e3e3; border-left: 1px solid #e3e3e3; background-color:transparent;}
Upvotes: 6
Views: 3420
Reputation: 1215
if you're using jQuery, you could use
$(".dropdown-toggle").blur()
to make it lose it's focus
For example:
JS:
var dropdown = $(".dropdown-toggle");
dropdown.on("click", function() {
setTimeout(function(){ //loses focus after 0 milliseconds
dropdown.blur();
}, 0);
});
Updated CSS:
#refine2 .dropdown-toggle:active {
background-color:transparent;
border:0;
}
#refine2 .dropdown-toggle:focus {
border-top: 1px solid #e3e3e3;
border-right: 1px solid #e3e3e3;
border-left: 1px solid #e3e3e3;
background-color:transparent;
}
#refine2 .dropdown-toggle{
background-color: transparent !important;
}
li.dropdown.open {
background-color: transparent;
}
Hope it helped :)
Cheers!
EDIT: I just saw this is a 7 month old question already... But I hope it'll still help someone else :)
Upvotes: 0
Reputation: 9372
Kind of old but you can solve this issue by putting the border on the list item instead.
Working example.
#refine2 .dropdown-toggle:active {
background-color:transparent;
border:0;
}
#refine2 .dropdown-toggle:focus{
background-color:transparent;
}
li.dropdown.open {
border-top: 1px solid #e3e3e3;
border-right: 1px solid #e3e3e3;
border-left: 1px solid #e3e3e3;
}
Upvotes: 0