=波波日志 > HTML/WML/CSS兼容/XML > firefox下button内嵌span会出现移位bug=

firefox下button内嵌span会出现移位bug

  在Firefox下,如果button内部嵌入span,button和span的display都为block,width,height都一致时,span无法完全遮盖住button控件,button和span会出现一些边距,在Firefox3.6下面,左边相差3px,顶部相差 2px,不知道是不是Firefox的bug。

  在IE浏览器和chrome浏览器下不会出现这种问题。

测试代码如下
+展开
-HTML
<style type="text/css">
.jsbutton {
            display:block;
            width:200px;
            height:40px;
            border:0px;
            background:#aaa;
            padding:0px;
        }
    
        .jsbutton span.hover {
            display: block; 
            width:200px;
            height:40px;
            background:#eee;
        }

</style> 
<button class="jsbutton"><span class="hover">123</span></button>


用javascript修正样式,增加margin控制


+展开
-HTML
<style type="text/css">
.jsbutton {
            display:block;
            width:200px;
            height:40px;
            border:0px;
            background:#aaa;
            padding:0px;
        }
    
        .jsbutton span.hover {
            display: block; 
            width:200px;
            height:40px;
            background:#eee;
        }

</style> 
<script type="text/javascript">
    //fix firefox,注意样式不能直接在上面的style中直接写,要用javascript判断下是否为Firefox再增加margin-left和margin-right,要不在ie或者chrome下就显示不正确
    if (/firefox/i.test(navigator.userAgent)) {
        document.write('<style type="text/css">.jsbutton span.hover {margin-left:-3px;margin-top:-2px;}</style>');
    }
</script> 
<button class="jsbutton"><span class="hover">123</span></button>
类别:HTML/WML/CSS兼容/XML 作者:波波 日期:2011-07-20 【评论:0】 
 
暂时没有评论!
发表留言
  • *昵称:
  • 头像:
  • 电子邮件: [留下您的邮件,方便管理员回复您。]
  • 个人网站: *验证码:
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载或引用的作品侵犯了您的权利,请通知我们,我们会及时删除!
Powered by showbo,©2012,桂ICP备05005887号 京公网安备1101055090