IE 7 中的 h2outerWidth 比 IE 8 短

发布于 2024-12-21 11:46:28 字数 492 浏览 2 评论 0原文

今天我在项目中实施修正时遇到了一个问题。

我发现 IE 7 中 h2 的外宽度比 IE8(FF、Chrome 等)中的短。

这是我的代码:

var h2width = $('.test h2').outerWidth(true)

h2width 在 IE8 中为 135px,在 IE7 中为 78px。

你对此有什么想法吗?

提前致谢!

编辑:

为了防止这个问题,我添加了区分浏览器的代码。

if ($.browser.msie && $.browser.version.substr(0, 1) <= 7) {
var h2width = $('.test h2').outerWidth(true) + 57;
} else {
var h2width = $('.test h2').outerWidth(true);
}

I have encountered a problem today when i imeplement a correction in our project.

What i found is that the outerWidth for h2 in IE 7 is shorter than in IE8 (FF, Chrome etc).

Here is my code:

var h2width = $('.test h2').outerWidth(true)

h2width is 135px in IE8 and 78px in IE7.

Do you have any ideas for that?

Thanks in advance!

Edit :

For prevent this problem, i have added the code for differenciate the browsers.

if ($.browser.msie && $.browser.version.substr(0, 1) <= 7) {
var h2width = $('.test h2').outerWidth(true) + 57;
} else {
var h2width = $('.test h2').outerWidth(true);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自控 2024-12-28 11:46:28

浏览器渲染 HTML 的方式不同,所以这并不奇怪。
使用Firebug或其他开发工具查看h2标签的实际大小。它们很可能是不同的。

另请注意,您的选择器 $('.test h2') 返回匹配元素的集合。

Browsers render HTML differently so this isn´t that strange.
Use Firebug or other development tool to view the actual size of your h2 tag. They are most likely different.

Also notice that your selector $('.test h2') returns a collection of matched elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文