css sprites:哪个 html 元素用于背景位置?

发布于 2024-10-02 21:51:27 字数 200 浏览 0 评论 0原文

我想知道使用 css sprites 哪个标签 html 最好?

我的意思是我可以使用

< img src="trasparent.png" style="background-position:ecc"> 或者 ?

我看到 Google 使用 <跨度> G"oooo o"gle 中的“o”

感谢

I am wondering for using css sprites which tag html is best?

I mean i can use

< img src="trasparent.png" style="background-position:ecc">
or ?

I saw Google using < span> for the "o" of G"o o o o o"gle

thanks

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

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

发布评论

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

评论(2

请帮我爱他 2024-10-09 21:51:27

您几乎可以使用任何您喜欢的元素。

但需要注意的一件事是,像 这样的元素是内联元素。因此,如果您尝试向它们添加尺寸以匹配背景精灵的大小,这些尺寸将被忽略。要解决此问题,您可以使用行高或填充等来设置尺寸,或者您可以使用 CSS 将元素更改为块级元素:display:block

另一个允许添加尺寸的规则是 display:inline-block,但这可能会在 IE6 和早期浏览器中导致一些问题。

You can use almost any element you like.

One thing to note though is that elements like <span> and <a> are inline elements. Thus if you try and add dimensions to them to match the size of your background sprite, these dimensions will be ignored. To fix this you can use things like line-heights or padding to set dimensions, or you could change the element into a block level element using the CSS: display:block.

Another rule that will allow dimensions to be added is display:inline-block, but this can cause a few issues in IE6 and earlier browsers.

东走西顾 2024-10-09 21:51:27

Google实际上正在使用span,根据我的经验也是一个不错的选择。

Google is actually using a span, in my experience is a good choice too.

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