jQuery:如何使css('line-height')跨浏览器工作

jQuery: how to make css('line-height') work cross-browser

本文关键字:浏览器 工作 line-height css jQuery 何使      更新时间:2023-09-26

我支持IE8及以上版本

$(something).css('line-height');

在Chrome中返回32px,但在IE8中返回normal

我如何绕过这个?也许是原生javascript变体?

似乎这是一个webkit vs. IE的问题。不确定FF,但有几个选项如何解决它。明确指定像素值也可以。但我不喜欢这样做,因为如果你根据媒体查询缩放文本等内容,就很难保持内容的比例。我能够通过公开指定em s中的行高来获得它的工作(而不是让它继承)。同样相关的是,它之前被设置为rem s, IE8不识别。

    function lineHeight(element){
       var tmp=$("<div>test</div>");
       element.append(tmp);
       tmp.css({"padding":"0","margin":"0","border":"0"});
       var height = tmp[0].clientHeight;
       tmp.remove();
       return height;
    }        

jsfield在FF和Chrome中返回20px,但在IE8中返回18px

相关文章: