我想知道是否有可能删除默认的蓝色和黄色辉光,当我点击一个文本输入/文本区域使用CSS?
当前回答
Carl W:
这种效果也会发生在非输入元素上。我发现下面是一个更通用的解决方案 :专注{ 边框色:透明; outline-style:没有; }
我来解释一下:
:focus意味着它对焦点中的元素进行样式化。因此,我们对焦点中的元素进行样式化。 边框色:透明;意味着蓝光是透明的。 outline-style:没有;做同样的事情。
其他回答
这种效果也会发生在非输入元素上。我发现下面是一个更通用的解决方案
:focus {
outline-color: transparent;
outline-style: none;
}
更新:您可能不必使用:focus选择器。如果你有一个元素,说<div id="mydiv">stuff</div>,你得到了这个div元素的外部发光,就像正常应用:
#mydiv {
outline-color: transparent;
outline-style: none;
}
这是为那些关心可访问性的人提供的解决方案。
请不要使用outline:none;用于禁用焦点轮廓。如果你这样做,你是在扼杀网络的可访问性。有一种可行的方法。
看看我写的这篇文章,它解释了如何以一种可访问的方式删除边界。
简而言之,当我们检测到键盘用户时,只显示轮廓边框。一旦用户开始使用他的鼠标,我们禁用大纲。结果你得到了两者中最好的。
<select class="custom-select">
<option>option1</option>
<option>option2</option>
<option>option3</option>
<option>option4</option>
</select>
<style>
.custom-select {
display: inline-block;
border: 2px solid #bbb;
padding: 4px 3px 3px 5px;
margin: 0;
font: inherit;
outline:none; /* remove focus ring from Webkit */
line-height: 1.2;
background: #f8f8f8;
-webkit-appearance:none; /* remove the strong OSX influence from Webkit */
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
/* for Webkit's CSS-only solution */
@media screen and (-webkit-min-device-pixel-ratio:0) {
.custom-select {
padding-right:30px;
}
}
/* Since we removed the default focus styles, we have to add our own */
.custom-select:focus {
-webkit-box-shadow: 0 0 3px 1px #c00;
-moz-box-shadow: 0 0 3px 1px #c00;
box-shadow: 0 0 3px 1px #c00;
}
/* Select arrow styling */
.custom-select:after {
content: "▼";
position: absolute;
top: 0;
right: 0;
bottom: 0;
font-size: 60%;
line-height: 30px;
padding: 0 7px;
background: #bbb;
color: white;
pointer-events:none;
-webkit-border-radius: 0 6px 6px 0;
-moz-border-radius: 0 6px 6px 0;
border-radius: 0 6px 6px 0;
}
</style>
如果你想移除Bootstrap中按钮的辉光(在我看来这并不一定是糟糕的用户体验),你需要以下代码:
.btn:focus, .btn:active:focus, .btn.active:focus{
outline-color: transparent;
outline-style: none;
}
有时也会发生按钮,然后使用下面来删除外线
input:hover
input:active,
input:focus,
textarea:active,
textarea:hover,
textarea:focus,
button:focus,
button:active,
button:hover
{
outline:0px !important;
}