CSS 图标带有一些语义文本、浏览器兼容性问题

发布于 2024-09-09 17:45:17 字数 474 浏览 0 评论 0原文

我使用此代码来显示精灵驱动的图标(如果图形可用,则仅应显示图标,对于其他设备,文本应该有所帮助):

标记:

<span class="icon ok">OK</span>

CSS:

.icon { display:block; width:16px; height:16px; padding-left:40px; overflow:hidden; background:transparent url(sprite.png) 0px 0px no-repeat; }
.ok { background-position: -16px 0px; }

精灵本身在任何浏览器中都可以正常工作,但是由于某种原因,文本显示在 Opera 和 Chrome 中,因为与溢出结合使用的填充:隐藏不会按预期工作。

有什么想法可以改进吗? 提前致谢....

I'm using this code to display sprite driven icons (if graphics are available only the icons should show up, for other devices the text is supposed to help):

Markup:

<span class="icon ok">OK</span>

CSS:

.icon { display:block; width:16px; height:16px; padding-left:40px; overflow:hidden; background:transparent url(sprite.png) 0px 0px no-repeat; }
.ok { background-position: -16px 0px; }

The sprite itself is working fine in any browser, but the text shows up in Opera and Chrome for some reason because the padding in conjuction with overflow:hidden won't work as supposed.

Any ideas how this could be improved?
Thanks in advance....

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

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

发布评论

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

评论(3

又怨 2024-09-16 17:45:17

通过将图像移出视线来隐藏图像的标准方法是使用 text-indent:-9999em 或类似的方法。对于 Opera 和 em 来说,它需要很大,因为它们会随着字体大小的变化而缩放。另外,设置 line-height:0; 也是个好主意。 font-size:0; 对于 ie,有时喜欢添加额外的空间。如果您使用 text-indent,则不需要填充来隐藏文本。

The standard way of hiding images by shifting them out of sight is to use text-indent:-9999em or something similar. It needs to really big for Opera and ems work well as they'll scale with any change in font size. Also it's a good idea to set line-height:0; font-size:0; for ie which sometimes likes to add extra space. You shouldn't need the padding to hide the text if you use text-indent.

陈独秀 2024-09-16 17:45:17

尝试使用负文本缩进。

.icon { display:block; width:16px; height:16px; text-indent: -9999px; background:transparent url(sprite.png) 0px 0px no-repeat; }

Try negative text-indent instead.

.icon { display:block; width:16px; height:16px; text-indent: -9999px; background:transparent url(sprite.png) 0px 0px no-repeat; }
孤星 2024-09-16 17:45:17

我不知道您是否只需要图标(16x16 框)或带有描述性文本的图标。不管怎样,如果你只需要 16x16 的盒子,你可以隐藏文本

.icon { display:block; width:16px; height:16px; background:transparent url(sprite.png) 0px 0px no-repeat; text-indent:-9999px; }

I don't know if you need just icon (16x16 box) or icon with descriptive text. Anyway, if you need just 16x16 box, you can hide text just by

.icon { display:block; width:16px; height:16px; background:transparent url(sprite.png) 0px 0px no-repeat; text-indent:-9999px; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文