【问题标题】:Why IE10 shows style differently than other browsers为什么 IE10 显示的样式与其他浏览器不同
【发布时间】:2014-03-31 14:55:32
【问题描述】:

我有以下 HTML:

<td class="tdGo" style="background-color: #0000FF;">
     <img src="theImages/search_go.png" id="imgGo" class="imgGo" />
</td>

CSS:

td.tdGo {
    padding-right: 24px;
    text-align: right;
}
.imgGo {
    cursor: pointer;
}

JQuery:

$('.imgGo').each(function() {
    var std = $(this).attr("src");
    var hover = std.replace("theImages/search_go.png", "theImages/search_go_rollover.png");
    $(this)
        .clone()
        .insertAfter(this)
        .attr('src',hover)
        .removeClass('imgGo')
        .siblings()
        .css({position:'absolute'});
    $(this)
        .mouseenter(function() {
            $(this).stop().fadeTo(250, 0);
        })
        .mouseleave(function() {
            $(this).stop().fadeTo(250, 1);
        });
});

IE10:

IE8:

FF/铬:

由于某种原因,在 IE10 中,图像出现在两个不同的位置,我似乎无法弄清楚为什么。任何帮助表示赞赏。

这是 DEV 工具显示的内容:

【问题讨论】:

  • 您检查过浏览器工具中呈现的 CSS 吗?
  • 我用开发工具截图更新了我的问题。
  • 这是一种非常时髦的翻转方式。该问题一定是您使用clone()引起的。
  • 你为什么不在 CSS 中做这个?无需使用 JavaScript 进行翻转。
  • 我希望在所有浏览器中都支持

标签: jquery html css internet-explorer-8 internet-explorer-10


【解决方案1】:

IE10 是唯一正确呈现此内容的:带有position:absolute 的元素不在流中,因此在确定其位置时不会响应text-align:right

考虑使用这个 CSS:

td.tdGo {
    text-align:right;
    padding-right:24px;
    position:relative;
}
.imgGoRollover {
    position:absolute;
    right:24px;
}

另外,请注意您的 jQuery 正在创建具有重复 ID 的元素 - 请确保从克隆的元素中删除 ID 属性。

【讨论】:

  • 我不会说其他浏览器是错误的 o_0,因为它并不完全尊重 text-align right,但更像是它记得它之前的位置并预设了 topleft 值,而不仅仅是 0。并不是说这是正确的做法,但是通过手动指定位置很容易修复(无论如何你都应该这样做,假设某些东西的默认值首先是危险的)
  • 我使用了:after 来确保转换正常工作。
猜你喜欢
  • 2011-11-21
  • 1970-01-01
  • 2014-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-10
  • 2020-05-13
  • 1970-01-01
相关资源
最近更新 更多