简体   繁体   English

只有键盘焦点时,如何才能为glymphicon图标应用CSS样式?

[英]How can I apply a CSS Style for a glymphicon icon ONLY when it has keyboard focus?

I have a glyphicon-star icon that operates as a checkbox. 我有一个glyphicon-star图标作为复选框操作。 When a user keyboard navigates to the star by tabbing, the star icon receives it's yellow css style for when it is the focused element. 当用户键盘通过Tab键导航到星形时,星形图标会在它是聚焦元素时接收黄色css样式。 The idea behind this is to simply show a user where they are located on a page. 这背后的想法是简单地向用户显示它们在页面上的位置。

HOWEVER, the problem that occurs is that when I click on the glyphicon-star icon, the star will retain a yellow color, even when tabbing to the next element. 然而,出现的问题是当我点击glyphicon-star图标时,即使标签到下一个元素,星形也会保持黄色。

How can I adjust the CSS to apply only for the keyboard navigation? 如何调整CSS以仅适用于键盘导航?

 <span ng-class="{'glyphicon glyphicon-star' : stack.favorite, 'glyphicon glyphicon-star-empty' : !stack.favorite}" style="float:right;padding-right:10px;padding-top:6px;"ng-click="toggleFavoriteStack(stack,'User');">
                                    </span>

.

.glyphicon.glyphicon-star:focus {   
color: yellow;
text-shadow: -2px 0 black, 0 2px black, 2px 0 black, 0 -2px black;
 }

.glyphicon.glyphicon-star-empty:focus {
color: yellow;
box-shadow: -2px 0 black, 0 2px black, 2px 0 black, 0 -2px black;
  }

你可以尝试:

input:not(:focus) { /* Styles for only form inputs that do not have focus */ }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM