CSS和JS去掉链接虚线框的多种方法_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:00:04
Original
1458 people have browsed it

当我们点击链接后,链接周围会显示一个虚线框,那么怎么去掉这个虚线框呢?其实方法还挺多,用CSS就可以,但使用javaScript似乎也是一个好方法。

1. CSS方式去掉链接虚线框的方法: 
在IE下是使用html属性:hideFoucs,在HTML标签中加上hidefocus=”true” 属性即可,但这个属性是IE私有的,Firefox是不认的。前端框架示例

.代码  

  1. 加了hidefocus属性  

 

IE中用CSS处理:

.代码  

  1. a{noOutline:expression(this.onFocus=this.blur());}/* "onFocus" 注意大小写*/  

 

Firefox的处理方法比较符合标准,只需要在CSS样式代码里设置a:focus{outline:none}皆可。接下来看一下MSIE和FF中统一处理的方法:

.代码  

  1. a{  
  2. outline:none; /*FF*/  
  3. noOutline:expression(this.onFocus=this.blur());/*IE*/  
  4. }  

 

考虑性能优化,可参考以下代码:

.代码  

  1. a{outline:none;}  
  2. a:active{noOutline:expression(this.onFocus=this.blur());}  
  3. :focus{outline:0;}  

 

2. 用js方式解决链接虚框的方法:前端框架示例

.代码  

  1. <script> </script>
  2. $("a").bind("focus", function(){  
  3. if(this.blur){  
  4. this.blur();  
  5. }  
  6. });  
  7.  
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!