在 Opera 和 Chrome 中,背景图像出现在前景图像之上

发布于 2024-08-24 10:51:01 字数 200 浏览 3 评论 0原文

我有一个带有背景图像的小跨度。该背景图像滚动到前景图像下方。虽然这在 IE 和 FF 中完美运行,但在 Opera 和 Chrome 中不起作用。

我已将示例放在此处。请看带有 4 个小矩形的块。

请提出解决方案。

I've a tiny span with a background image. This background image scrolls below foreground image. While this works perfectly in IE and FF, it doesn't work in Opera and chrome.

I've put my example here. PLease see the block with 4 small rectangles.

PLease suggest solution.

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

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

发布评论

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

评论(1

暖风昔人 2024-08-31 10:51:01

您需要将 display:block 添加到您的范围中。

<span style="display:block; background: url("/resources/images/strength_bgr.gif") no-repeat scroll 0pt -20px transparent;">
  <img alt="test" src="/resources/images/strength.gif">
</span>

内联元素没有高度或宽度,因此会显示整个背景,而不是根据图像大小进行裁剪。


评论后编辑

是否有任何原因无法将背景图像应用到 img 标签本身?这将在跨浏览器上更加一致。

You need to add display:block to your span.

<span style="display:block; background: url("/resources/images/strength_bgr.gif") no-repeat scroll 0pt -20px transparent;">
  <img alt="test" src="/resources/images/strength.gif">
</span>

Inline elements do not have a height or width so the whole background is being displayed instead of being cropped by the image size.


Edit after comments

Is there any reason you can't apply the background image to the img tag itself? That would be more consistent cross-browser.

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