2009-09-20 42 views
14

我相信我在WebKit中发现了一个错误。它涉及到jQuery中的outerWidth(true)(我假设outerHeight(true))。我想我在WebKit(或jQuery)中发现了一个bug,其他人可以证实吗?

在除Safari和Chrome之外的每个浏览器中,第三个框为200.在Safari和Chrome中,它几乎是我的屏幕宽度。

点击here看我的结果: inline image not found. http://x3non.com/image/alec/147/outerWidth%20true%20fail.png

您可以测试自己的位置:http://ramblingwood.com/sandbox/webkit-bug/test.html

我用这个测试文件:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
    <style type="text/css"> 
    input { 
     width: 50%; 
     height: 1em; 
     font-size: 1em; 
    } 
#testBox {margin-left:100px;width:100px;} 
#testBox2 {padding-left:100px;width:100px;} 
#testBox3 {border-left:100px black solid;width:100px;} 
    </style> 
    <script type="text/javascript"> 
    function init(){ 
     $('#w1').val($('#testBox').width()); 
     $('#ow1').val($('#testBox').outerWidth()); 
     $('#owt1').val($('#testBox').outerWidth(true)); 
     $('#w2').val($('#testBox2').width()); 
     $('#ow2').val($('#testBox2').outerWidth()); 
     $('#owt2').val($('#testBox2').outerWidth(true)); 
     $('#w3').val($('#testBox3').width()); 
     $('#ow3').val($('#testBox3').outerWidth()); 
     $('#owt3').val($('#testBox3').outerWidth(true)); 
    } 
    $(document).ready(function(){ 
     init(); 

     $(window).resize(function(){ 
     init(); 
     }); 
    }); 
    </script> 

</head> 
<body> 
<div id="testBox">test</div> 
    <p>width() <input type="text" id="w1" /></p> 
    <p>outerWidth() <input type="text" id="ow1" /></p> 
    <p>outerWidth(true) <input type="text" id="owt1" /></p> 

<div id="testBox2">test2</div> 
    <p>width() <input type="text" id="w2" /></p> 
    <p>outerWidth() <input type="text" id="ow2" /></p> 
    <p>outerWidth(true) <input type="text" id="owt2" /></p> 

<div id="testBox3">test3</div> 
    <p>width() <input type="text" id="w3" /></p> 
    <p>outerWidth() <input type="text" id="ow3" /></p> 
    <p>outerWidth(true) <input type="text" id="owt3" /></p> 
</body> 
</html> 

回答

11

Chrome的DOM检查器确认这是一个WebKit问题;即使您尝试覆盖margin-right,div也会获得较大的右边距。有些东西强制保证金计算正确包括float: leftdisplay: inline-block。另外,如果您将div放在另一个大小的div内,它的outerWidth(true)将给出包含div的innerWidth,这可能是一个有用的真实世界的解决方法 - 只需将其包装在margin: 0; padding: 0; width: XXX的div中即可。

1

这不是在寻找一个bug外部宽度。 Webkit实际上使得divs具有很大的右边距。由于右边距(几乎)延伸到右边缘,因此可以获得更大的外部宽度。

我不确定这是否是“正确”的渲染方式,但如果有一个说明右边距不应该延伸的规范,那么这将是WebKit中的一个错误。

+1

在任何情况下,真的是fricken编写跨浏览器的代码时烦人。 – 2009-09-20 03:08:23

0

我也可以证实这一点。

Webkit这样做真的很奇怪,我无法想象为什么有人会认为这是一个好主意。

我不知道Chrome 4是否修复此问题。

1

我的经验也证实了这一点 - 这是一个Webkit的bug,需要修复。

1

,如果你设置的大小说1对您输入字段它修复了这个bug - testet在Chrome和Safari

相关问题