为什么 IE7 会在鼠标悬停时移动 DOM 元素?

发布于 2024-11-16 13:30:11 字数 436 浏览 2 评论 0原文

所以我有一个只有两列和一行的表。第二个 td 保存图像,第一个 td 保存文本。我希望包含图像的 td 尽可能具有该图像内部的最小尺寸,并且第一个 td 填充剩余空间。以下内容适用于除 IE7 之外的所有浏览器(我们不使用 IE6):

; < /tr>

文本jpg

发生的情况是这样的: 页面渲染正确,然后当您将鼠标悬停在表格上时,第一个 td 会展开以填充整个表格,将图像推离边缘。

我可以用一些 jQuery 来解决这个问题,以测量图像的宽度并计算第一个 td 的余数;但这个解决方案充满了蹩脚!

请帮忙。我不明白为什么 IE7 觉得需要重绘它的方式。

So I have a table with only two columns and one row. The second td holds an image, and the first holds text. I would like the td containing the image to be at the minimum size possible with that image inside, and the first td to fill the remaining space. The following works in every browser except IE7 (we are not doing IE6):

<table> <tr><td style="width:100%;">TEXT</td><td><img src="jpg" alt="jpg" /></td></tr> </table>

What happens is this:
The page renders correctly, then when you mouse over the table, the first td expands to fill the entire table, pushing the image off the edge.

I could fix this with some jQuery to measure the width of the image and calculate remainder for the first td; but that solution is full of LAME!

Please help. I do not understand why IE7 feels the need to redraw the way it does.

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

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

发布评论

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

评论(5

不羁少年 2024-11-23 13:30:11

请尝试使用以下代码。不要显式地声明太多宽度,而是尝试显式地声明太少(因为无论如何图像都会将宽度推到 1% 以上。

)家里的虚拟机,所以如果我找到不同的解决方案,我稍后会发表评论。

<table style="width: 100%;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>TEXT</td>
<td width="1%" style="width: 1%;"><img src="http://www.google.com/intl/en_com/images/srpr/logo2w.png" alt="Google Logo" /></td>
</tr>
</table>

Try the following code instead. Instead of explicitly declaring too much width, try explicitly declaring too little (because the image will push the width beyond 1% anyway.)

I am writing this off the top of my head without actually having looked in IE7, but I have IE7 in a Virtual Machine at home and so I'll comment back later if I find a different solution.

<table style="width: 100%;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>TEXT</td>
<td width="1%" style="width: 1%;"><img src="http://www.google.com/intl/en_com/images/srpr/logo2w.png" alt="Google Logo" /></td>
</tr>
</table>
梦一生花开无言 2024-11-23 13:30:11

您可以尝试以下几项操作:

  1. 确保使用reset.css 样式表来重置所有浏览器默认设置并适应任何浏览器怪癖。这对于 Internet Explorer 尤为重要。
  2. 仅将表格用于表格数据 - 我不确定表格的其余部分包含什么,但除非有数据行,否则使用带有 div 的容器会更容易code>p 和 img 浮动。
  3. 设置 img 的宽度和高度。
  4. 使用 CSS position:relative; float: left; 看看它是否有助于解决悬停时的定位问题。我经常看到 jQuery 脚本和 CSS3 PIE 等浏览器黑客的悬停问题 - 如果您正在使用这些,请尝试删除它们。

There are a couple of things that you could try:

  1. Make sure you're using a reset.css stylesheet to reset all of the browser defaults and accommodate any browser quirks. That's especially important with Internet Explorer.
  2. Only use tables for tabular data — I'm not sure what the rest of your table contains, but unless there's going to be rows of data, it would be much easier to use a container div with a p and img floated.
  3. Set the width and height on the img.
  4. Use CSS position: relative; float: left; to see if it helps with positioning issues on hover. I see hover issues a lot with jQuery scripts and browser hacks like CSS3 PIE — if you're using those, try removing them.
智商已欠费 2024-11-23 13:30:11

尝试在元素上设置 style="zoom:1"

Try setting the style="zoom:1" on the element.

眼泪也成诗 2024-11-23 13:30:11

我不确定,但从

<table> <tr><td style="width:100%;">TEXT</td><td><img src="jpg" alt="jpg" /></td></tr> </table>

我所看到的来看,这上面没有表格宽度,所以 IE 不知道如何适当地缩放 td。

另一种猜测是因为您在第一个上将宽度声明为 100%,IE 会将其解释为将其推开。我的猜测是,第一个单元格的宽度不能为 100%,因为这意味着占用整个表格宽度的 100%。

I am not sure but looking at

<table> <tr><td style="width:100%;">TEXT</td><td><img src="jpg" alt="jpg" /></td></tr> </table>

from what I can see is that there is no table width on this, so IE does not know how to scale the td appropriately.

Another guess is because you're are declaring width as 100% on the first one IE interprets this to shove it off. Which is my guess, you can not have a width of 100% on the first cell because it means to take up 100% of the full table width.

野侃 2024-11-23 13:30:11

清除浏览器缓存,在图像上指定宽度和高度

我在 ie7 上看到了最奇怪的东西,例如分页符 \n 等导致此效果的原因,即:

<a href="#>
<img src="jpg" />
</a>

修复只需将所有内容放在同一位置即可行且不带空格(就像右侧有空格的表格)

也避免使用内联样式,使用样式表(css)

clear you browser cache, specify a width and height on your image

i have seen the most weird stuff on ie7, like pagebreaks \n and such causing this effect, ie:

<a href="#>
<img src="jpg" />
</a>

to fix just put everything on the same line and without spaces (like your table with a space on the right)

also avoid using inline style, use a stylesheet (css)

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