有什么关于 css sprites 的例子吗?

发布于 2024-08-18 22:38:06 字数 98 浏览 3 评论 0原文

我了解 css sprites.. 现在我想要一些 css sprites 的例子....

  • 你是如何设法让 css sprites 工作的?

I know about css sprites.. Now i want some examples of css sprites....

  • How did you manage to get css sprites work?

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

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

发布评论

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

评论(6

小嗲 2024-08-25 22:38:06

我通常使用 CSS 背景属性。此属性允许您设置顶部和左侧的滚动参数,如下面的示例所示。因此,我们的想法是创建一个具有所有状态的图像,并根据悬停事件或其他更改元素 CSS 的自定义事件简单地定位它。我希望这有帮助。

.mySprite a
{
    background: transparent url(/images/spriteButton.gif) no-repeat scroll 0 0
}

.mySprite a:hover
{
    background: transparent url(/images/spriteButton.gif) no-repeat scroll 30 0
}

I usaully use the CSS background property. This property allows you to set a scroll argument of top and left as you can see in the example below. So the idea is to create one image with all states and simply position it based on the event like hover or other custom event in which you alter the elements CSS. I hope this helps.

.mySprite a
{
    background: transparent url(/images/spriteButton.gif) no-repeat scroll 0 0
}

.mySprite a:hover
{
    background: transparent url(/images/spriteButton.gif) no-repeat scroll 30 0
}
金兰素衣 2024-08-25 22:38:06

如果您使用 Firefox,这里有一个简单的方法来了解精灵是什么。转至 yahoo.com,右键单击并查看页面信息,然后单击媒体。查找其中包含“sprite”的文件名。

这是链接之一:
http://d.yimg.com/a/i/ww/ met/gsprite_071309.gif

您将看到许多背景渐变图像。您可以使用该文件来玩。现在,您必须根据要使用的背景调整 CSS 中的背景位置,如下所示:

background-image: url('http://d.yimg.com/a/i/ww/met/gsprite_071309.gif') left -30px repeat-x;

这应该让您了解如何管理精灵。

If you are using Firefox here is a simple way to get an idea of what a sprite is. Go to yahoo.com, right-click and View Page Info, click Media. Look for a file name having "sprite" in it.

This is one of the links:
http://d.yimg.com/a/i/ww/met/gsprite_071309.gif

You will see many background gradient images. You can use this file to play with. Now you have to adjust background position in your CSS depending on which background you want to use, like this:

background-image: url('http://d.yimg.com/a/i/ww/met/gsprite_071309.gif') left -30px repeat-x;

This should give you an idea of how to manage sprites.

演多会厌 2024-08-25 22:38:06

如果您想创建 CSS 精灵 - 您可以访问 spriteme.org 网站,该网站非常酷,并向您展示了如何轻松创建 CSS 精灵。

对于一个很好的例子,您可以查看此页面:

http://www.programmerinterview.com/index.php/general-miscellaneous/css-sprite-example-and-tutorial/

给出了很好的解释并展示了网站所有者如何使用精灵。

If you are looking to create a CSS sprite - you can check out the site spriteme.org, which is very cool and shows you how to easily create a CSS sprite.

For a nice example you can check out this page:

http://www.programmerinterview.com/index.php/general-miscellaneous/css-sprite-example-and-tutorial/

Gives a good explanation and shows how the website owner uses a sprite.

三生路 2024-08-25 22:38:06

我将它们用于按钮图像。我将图像的上半部分用于正常按钮状态,将下半部分用于鼠标悬停状态。这样,当页面加载时,鼠标悬停在图像上的图像就会被加载,并且没有延迟,这看起来很糟糕而且很慢。 CSS 代码位于此处。

I use them for button images. I use the top half of an image for the normal button state and the bottom half for the mouse-over state. That way the mouse over image is loaded when the page loads and there's no delay which just looks bad and slow. CSS code is here.

柠檬心 2024-08-25 22:38:06

查看此页面:

http://www.tutorialrepublic.com/css-tutorial/ css-sprites.php

它有一个很棒的交互式示例以及您需要了解的有关 CSS Sprite 的所有信息。

Check out this page:

http://www.tutorialrepublic.com/css-tutorial/css-sprites.php

It has a great interactive example and everything you need to know about CSS Sprite.

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