/*
* 注意:由于我们的demo页面采用的noreset.css重置样式包含对虚线框的重置(代码如下)---点击时没有虚线框,但是聚焦状态是有的
* 故本页面注释了noreset样式的引用,方便测试虚线框的情况!
*/
/*
* Addresses `outline` inconsistency between Chrome and other browsers.
*/
a:focus {
outline: thin dotted;
}
/*
* Improves readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0;
}
查看详细分析:页面的易用性:为什么不推荐去掉链接周围的虚线框
<a href="#" hidefocus="true">A outline:hidefocus</a>
/* hack for Firefox */
input[type=submit]::-moz-focus-inner,input[type=button]::-moz-focus-inner{
border : 0px;
}
/* 不要随便去掉虚线框 */
input[type=submit]:focus, input[type=button]:focus{
outline : none;
}
IE 需要在标签中添加 hidefocus 属性,值可以为空,如:<input href="#" hidefocus value="确定" type="button" />,<a /> 标签同理。
我能在用 TAB 键的时候不去掉虚线框吗?为什么我的 input 在 firefox 下没有成功去除虚线框?这些问题被提出的时候,困扰着不少人。因为这里面有潜规则。总结一下,看这个表:
| 去除的方式 | 生效的浏览器 |
|---|---|
| outline:none | IE8 | Firefox | Webkit |Opera |
| hidefocus | IE |
| :focus{outline:none;} | IE8 | Firefox | Webkit | Opera |
| :active{outline:none;} | 同上,但在tab的时候,IE将保留虚线框 |
| ::-moz-focus-inner{outline:none;} | Firefox 存着bug,input 须要去这个伪状态下的边框 |
更多:详见去除虚线框介绍
/* 去除虚线(部分元素) */
$(".no_focus").bind("focus",function(){
//if(document.all){ //针对IE
if(this.blur){
this.blur(); //常用于幻灯的数字按钮
};
});