2015-09-28 22 views
0

在此先感谢。文字宽度在Chrome和Firefox中不同

JS小提琴链接:http://jsfiddle.net/XpPpR/46/

这里是我的代码,

<script src="Hide_3d5b7aca/Hide/jquery-1.9.1.min.js"></script> 
<div id="measureText"/> 
    <script> 
     $(function() { 
      text = "1 000 000"; 
      font = { 
       color: '#282828', fontFamily: 'Segoe UI', fontStyle: 'Normal', fontWeight: 'regular', opacity: 1, size: '13px' 
      }; 
      var element = $(document).find("#measureTex"); 
      if (element.length == 0) { 
       var textObj = document.createElement('text'); 
       $(textObj).attr({ 'id': 'measureTex' }); 
       document.body.appendChild(textObj); 
      } 

      textObj.innerHTML = text; 

      if (font != null) { 
       textObj.style.fontSize = (font.size > 0) ? (font.size + "px") : font.size ; 
       textObj.style.fontFamily = font.fontFamily ; 
      } 

      alert(textObj.offsetWidth); 

     }); 
    </script> 

的文本宽度显示为Chrome和Firefox 57,但在IE它返回的56 为什么呢?以及如何解决这个问题。

回答

2

没有办法在不同的浏览器中获得相同的文本宽度。这是因为字体渲染系统非常不同,尤其是OS X和Windows。

更多信息:http://www.smashingmagazine.com/2012/04/a-closer-look-at-font-rendering/

+0

这个信息有什么来源? –

+0

@AkbarBasha,请查看这篇文章,例如:http://www.smashingmagazine.com/2012/04/a-closer-look-at-font-rendering/ – IonDen

+0

感谢您的信息 –

相关问题