Any examples to know about css sprites?

拥有回忆 提交于 2019-12-22 00:13:37

问题


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

  • How did you manage to get css sprites work?

回答1:


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
}



回答2:


http://stylemeltdown.com/2007/10/22/image-sprite-navigation-with-css/

http://www.w3schools.com/css/css_positioning.asp

http://template.joomlart.com/ja_iris/index.php?option=com_content&view=section&layout=blog&id=4&Itemid=29




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/2144908/any-examples-to-know-about-css-sprites

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!