Build Internet has a brand new theme, and that's only the beginning. Read the full story or hide this bar

How to Make a CSS Sprite Powered Menu

How to Make a CSS Sprite Powered Menu

We haven’t gone back to basics in a while.

Today’s tutorial will bring you through the process of building a slick menu using a single CSS sprite image. It’s a simple, but elegant solution for most websites. This was one of the design strategies that first helped me to start using smarter markup. For those of you just getting introduced to this technique today, hopefully you’ll have some similar results.

The end goal is to create a navigation menu that loads quickly, and does not require any dated JavaScript for hover effects. If you’re still using individual images for each menu item, it’s time to upgrade.

The Goal

This CSS sprite will keep HTTP requests down and increase load speed. For a more in depth explanation of CSS Sprites, take a look at Chris Coyier’s article on CSS Tricks. He goes into a wider variety of uses, but this tutorial will focus on getting the navigation done for simplicity’s sake.

The end result

Design the Menu

Breaking from the usual flow of tutorials, we’re going to take a look at part of the Photoshop process before hitting the code. This is in order to demonstrate a simple way of measurement and markers for the menu’s sprite design.

Love the Grid

Rulers and markers are your best friend when it comes to CSS sprites. To take advantage of these guides in Photoshop, turn on rulers through the View>Rulers option in the toolbar. Once rulers are active, you can create a new guide by click on the ruler and then dragging onto the composition area. These guide lines can be used to align your sprite. Alternatively, you can activate the grid overlay through View>Show>Grid.

Guides in Photoshop

In order for the positioning to work in CSS, you’ll need to know the rough coordinates of each menu item inside the sprite. I’ve found it easiest to pick a measurement system that it consistent instead of minimal.

To put it another way, I would much rather remember 100px, 200px, etc than 101px, 342px, etc. Blocking your sprite out in a logical grid also makes future changes significantly less painful, and often requires less adjustment. You can find the example sprite image that I use for this tutorial at the bottom of this post in the source files.

Structure with HTML

The code below will set up a basic menu structure for us to work with in CSS. Feel free to start a new file or insert into an existing menu.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>CSS Sprite Navigation</title>
	<link rel="stylesheet" href="css-sprites-nav.css" type="text/css" />

</head>

<body>

		<ul id="menu">
			<li class="home"><a class="selected" href="#">Home</a></li>
			<li class="about"><a href="#">About</a></li>
			<li class="contact"><a href="#">Contact</a></li>
		</ul>

</body>
</html>

A Brief Word on SEO

Our top navigation menu will be structured as a list to keep semantic code. Keep in mind that because these list items will only be displaying an image. The hidden overflow and negative text indent will hide any text from the user’s view. We do not want to leave them blank, because that would give search engines less content to crawl. Even though the images will have text, the search engine will not be aware of this unless we give it actual code to reference.

The Big Idea: As designs become more graphic intense, it is ok to use images (in moderation) as text replacement for elements like navigation, banners, button, etc. If you choose to do this, you still have to account for the search engines.

Position Images with CSS

Copy the code below into your CSS file for the project. An explanation will follow.

/* Everything CSS Sprite Menu */
	ul#menu{margin:0; padding:0; list-style:none; clear:both;}
		#menu li{overflow:hidden; text-indent:-9999px; display:inline; float:left; margin-right:10px;}
			#menu li a{background:url('images/menu-sprite.jpg') no-repeat; width:100%; height:100%; display:block;}

			/* Home Button */
			#menu li.home{width:115px; height:60px;}
				#menu li.home a{background-position:-5px -5px;}
				#menu li.home a:hover{background-position:-5px -75px;}
				#menu li.home a.selected{background-position:-5px -145px;}

			/* About Button */
			#menu li.about{width:120px; height:60px;}
				#menu li.about a{background-position:-125px -5px;}
				#menu li.about a:hover{background-position:-125px -75px;}
				#menu li.about a.selected{background-position:-125px -145px;}

			/* Contact Button */
			#menu li.contact{width:160px; height:60px;}
				#menu li.contact a{background-position:-250px -5px;}
				#menu li.contact a:hover{background-position:-250px -75px;}
				#menu li.contact a.selected{background-position:-250px -145px;}

Change Image with Background Position

The background-position CSS property allows you to specify a set of coordinates on the background image. The benefit of this is that you can load a single background image for a number of elements, but give individual ones their own coordinates. This property is the backbone of CSS sprites.

You’ll remember that we gave each menu list item its own class. This allows us to target them individually for background image coordinates. The background image has already been defined by the general anchor tag style, so the only change that needs to be made for each menu item is the positioning. Especially on larger projects, keeping down the number of redundant styles is key to keeping sanity.

Using this method, we created three unique states for the navigation:

  1. Default is displayed to start
  2. Hover is activated by mouseover
  3. Selected indicates the current page location. It can be activated by a special “selected” class assignment

Unless you’re building something out of the ordinary (e.g. multi-tiered menu), you’d have a hard time needing anything past these three states.

Wrapping Up

By this point you should have a menu driven by a single image. As Chris Coyier’s article brings up, this lowers HTTP requests and allows a smoother loading experience than a long list of bulky separate files for each element. Condensing is good for pages.

I’ve put together a ZIP file of source code and demo for further help. The example in the file is a little more comprehensive, but still follows the principles of this tutorial. Having any errors or confusion about the process? Leave a comment below and we’ll try to sort things out.

Wordpress.com stats not installed! Posted Tuesday, January 26th, 2010 / Back to Top

I this post. Tweet
SPONSOR

108 Comments 64 Mentions

  1. Eric B. Author Editor

    CSS sprites are really one of the best things ever that I have discovered! They’re not too hard to make, and make everything go much more quickly.

    I’m actually currently in the process of converting someone’s old navigation menu consisting of an image for each navigation menu item, an image for each hover state, using Javascript for a basic hover effect like the one in this demo. *shudder*

    Thanks for this nice and helpful tutorial.

    January 26, 2010 · Reply

  2. Montana Flynn Author Editor

    Thanks for going over CSS sprites, I used a similar technique today.

    January 26, 2010 · Reply

  3. Melvin José Author Editor

    Would love to see a detailed explenation of the “a.selected” technique.

    January 26, 2010 · Reply

  4. Gustavo Guichard Author Editor

    Unfortunately if you’re using PNG with background-positioning, it won’t be transparent on IE6. This is sad!

    January 26, 2010 · Reply

  5. Hunter Satterwhite Author Editor

    Really nice and simple.
    @Gustavo I’m sure a javascript PNG fix would let IE6 join the party with out a problem.

    January 26, 2010 · Reply

  6. Gustavo Guichard Author Editor

    @Hunter, Any suggestions?

    January 26, 2010 · Reply

  7. Hunter Satterwhite Author Editor

    @Guastavo sure thing! Andreas Eberhard has written a very nice jQuery plugin to fix png’s. He’s even included various instructions in the file heading on how to use it on document load and in noconflict mode.
    http://jquery.andreaseberhard.de/pngFix/index.html

    January 26, 2010 · Reply

    • Zach Dunn Author Editor

      Thanks for the help Hunter!

      January 26, 2010 · Reply

      • ashutosh Kumar Author Editor

        saving images in PNG24 takes care of IE6 rendering problem…no hack needed.

        March 22, 2012 ·

  8. Vel Author Editor

    I’d add a.selected {cursor: pointer;} in css to make selected link to look like tab, and not link :)

    January 26, 2010 · Reply

  9. Gustavo Guichard Author Editor

    @Hunter, Thanks buddy!
    @Vel, I think it’s nice the way it is… Just thought

    January 26, 2010 · Reply

  10. güvercin Author Editor

    this is wonderfull example .. thanx gay!

    January 26, 2010 · Reply

  11. Saw Htoo Author Editor

    Thanks for the post. I have never used that technique before. Thanks! :)

    January 26, 2010 · Reply

  12. e11world Author Editor

    This is the first time I actually consider using this method just because you made it look so easy. I guess I also never bothered with it that much but your explanation and code is easy to understand. Thanks!

    January 26, 2010 · Reply

  13. BigM75 Author Editor

    nice article, cool plugins

    January 26, 2010 · Reply

  14. Ardit Veliu Author Editor

    I use spriting for most of my projects but the way I originally learned it seems my CSS ends up a little bulkier than yours, going to have to look into that.
    p.s. My first time commenting here and the comment box is pretty awesome.

    January 26, 2010 · Reply

  15. Wayne Author Editor

    if you have fireworks it can do all the html/css/math for you with this cool plugin:

    http://www.andrewingram.net/articles/generating_sprite_navigation_from_fireworks/

    January 26, 2010 · Reply

  16. Hunter Author Editor

    @Vel nice idea! Now we should tie in some jQuery to make it fadein/out or ease some how to give it that little bit of “oomph” that people enjoy.

    January 27, 2010 · Reply

  17. Ward Author Editor

    Nice tutorial. Going to be using this a lot;)

    January 27, 2010 · Reply

  18. Webstandard-Blog Author Editor

    Nice posting Zach, but I’m not a friend of Sprites with text-content in it. You have to update the sprite-graphic every time your navigation is updated with new or changed “content”. If you develop multi-lingual projects, this kind of sprites aren’t the best solution.

    January 27, 2010 · Reply

    • BertieorBirdie Author Editor

      I could watch Schdilenr’s List and still be happy after reading this.

      September 20, 2011 · Reply

  19. Hunter Author Editor

    @Webstandard-Blog good points, but is it really that much trouble to update a navigation bar with the way we do things today?

    If you’re worried about custom fitting text in different languages, than why not use something like sIFR to achieve the look and feel of the text and maybe expanding the sprite to include small, medium, and large size graphics to accommodate varied text sizes.

    January 27, 2010 · Reply

  20. Webstandard-Blog Author Editor

    @Hunter: Sprites are a good decision, thats not the question, but I would prefer a solution with just the “bottom-part” of the tabe images, rest of it made by text and css. So you aren’t addicted to the image or the language, if you know what I mean.

    By the way sIFR, would be a nice solution too and thx for your feedback!

    Greetings from Berlin ;o)

    January 27, 2010 · Reply

  21. Hunter Author Editor

    @Webstandard-blog oooooh yea just the “bottom-part”, now that just simplifies the whole process and combined with sIFR you’ve got a design easy to manage across different languages. It would even be great for using word as long as “Donaudampfschiffahrtsgesellschaftskapitän”. :)

    January 27, 2010 · Reply

  22. Ed Baxter Author Editor

    A great tutorial. I think if you can use them right sprites can help your site so much. My only concern is using text inside the graphic. I know that this is not an issue in terms of SEO due to the text-indent CSS however it can make things trickier if you have lots of sprites and need to keep opening Photoshop to change the text around.

    Great tutorial never the less!

    January 27, 2010 · Reply

  23. josekerekes Author Editor

    In case we want to use png images with alpha transparency in a sprite in ie6, we will encounter a problem.Using filter alphaImageloader is a solution to our problems but filter does not have background positioning.Fortunatelly the belatedPng script comes to our rescue, saving the day.It uses vml to handle png -s and yes it can handle background-positioning.If you are not bothered to use a script for fixing ie6 bug for suporting alpha transparency, or you don’t care about ie6 then everyting is allright.

    January 28, 2010 · Reply

  24. reza Author Editor

    i’ll use

    #menu li.home a:active{background-position:-5px -145px;}

    instead of

    #menu li.home a.selected{background-position:-5px -145px;}

    January 28, 2010 · Reply

  25. Benjamin Walsh Author Editor

    Anyone else notice that this isn’t working in ie8? Unless its on the fritz again.

    January 28, 2010 · Reply

  26. Webdesign Rosenheim Author Editor

    Grrreat tut!
    I’ll try this on the next webdesign project!
    Thanks for sharing!

    January 28, 2010 · Reply

  27. jitendra vyas Author Editor

    oh, nothing is showing if images is disabled. i usually surf with images disabled because i’ve very low internet conncetion and i keep images disabled in my mobile phones browser also to save bandwidth.

    It would be better if upon images disabled atleast simple hyperlink should be shown

    January 28, 2010 · Reply

  28. Tutorijali HDonWEB Author Editor

    Great css tutorial :-)

    January 29, 2010 · Reply

  29. Michael Szczepanski Author Editor

    Very simple and a great starting point. Thanks!

    February 1, 2010 · Reply

  30. Complain.O.matic Author Editor

    I will be using this on my companies site when I do their redesign. As usual great tutorial.

    February 2, 2010 · Reply

  31. manidf Author Editor

    nice one.

    February 3, 2010 · Reply

  32. zur4ik Author Editor

    nice :))

    February 7, 2010 · Reply

  33. Ezrad Lionel Author Editor

    In case anyone was wondering just how many sprites you could stick together, don’t bother trying with background-image. you’ll end up with a 2 second clip that bogs down your cpu. i have a method that gets infinite (depends on your pc ram) frames with virtually no cpu use. an example of a short sub 30 frame clip with dispersed frame interleaving for stress tests.

    http://novatvmedia.com/vved

    type v-v-e-d to see stats, try out in different browsers. and if you happen to try using your own tiles you’ll realize that yes indeed, internet explorer is shitting on the benchmark. notice also the sporadic nature of most rendering engines especially chrome.

    February 10, 2010 · Reply

  34. tuna Author Editor

    simple and nice, thanks..

    February 11, 2010 · Reply

  35. Nicole Author Editor

    Hi!

    thanks for that great tutorial. It was really easy to implement the css sprites (I finally understood how they work :)) and works like a charm.

    Nicole

    February 18, 2010 · Reply

  36. Mark James Author Editor

    Excellent tutorial, only just found out about this method! Will definately give it a go

    February 19, 2010 · Reply

  37. webdesign tom Author Editor

    wow, nice tut! thanks a lot, i’m going to use this technique! Does ist also work on my best friend IE?

    February 24, 2010 · Reply

  38. jakobsweg pilgern Author Editor

    thanks for this tut!
    sure, css sprite is the best way to implement hover effects!

    February 24, 2010 · Reply

  39. Hian Battiston Author Editor

    Simply an great tutorial! Thanks

    March 5, 2010 · Reply

  40. Onigiri Author Editor

    indeed a great tutorial, i was able to make my first ‘sprited menu’ thanks to it.
    I have a big question though: how would you add submenus to some of the menu items? I’ve been looking all over the net but can’t seem to find a solution…PLEASE HELP!!

    March 9, 2010 · Reply

    • Zach Dunn Author Editor

      @Onigiri

      That’s far outside the specification of this tutorial. I recommend you create a secondary div which is replaced using jQuery based on which menu item is selected. Past that, I think you’d be best suited with a Google search.

      March 11, 2010 · Reply

  41. webseite erstellen Author Editor

    I studied the css tutorial and I really learned a lot. I think my next homepage will be a lot better than my first one.

    April 7, 2010 · Reply

  42. Rob Author Editor

    I suppose you could use the same principle to make seo friendly h2′s etc, would just mean a pain if you wanted to change the text in your CMS.

    April 21, 2010 · Reply

  43. Sas Author Editor

    @Hunter: I have a page with CSS spites and jquery.pngFix.js doesn’t work properly unfortunately… It’s scaling all backgrounds and I see the whole sprite-image everywhere… :( …or I did any mistake?!

    Any suggestion?

    April 22, 2010 · Reply

  44. Juegos Author Editor

    You guys rock, very useful trick. Thank you.

    April 28, 2010 · Reply

  45. Barry Author Editor

    Great tut Zach. Just what I needed, nice+concise.

    May 28, 2010 · Reply

  46. wantfee Author Editor

    That is lovely. Thanks!

    June 11, 2010 · Reply

  47. Ryan Fitton Author Editor

    Hi i loved this tutorial but how could i make the menu center itself to my webpage but keep centered when i alter the width of the browser?

    July 1, 2010 · Reply

  48. Zeoplan Author Editor

    Thanks :)

    July 24, 2010 · Reply

  49. Web Design Hippo Author Editor

    Thanks for this, real helpful. I have only used a similar technique recently!

    August 4, 2010 · Reply

  50. Richard Schroder Author Editor

    Zach Dunn … a prince amongst men for this tutorial.

    Thank you for the plain English.

    Worked first time for an intern using her own images.

    Good show!

    (spontaneous note)

    August 12, 2010 · Reply

  51. volkan Author Editor

    good menu

    September 3, 2010 · Reply

  52. Rizwan Javaid Author Editor

    Very nicely explained. Great graphics.

    Thanks guys!

    September 16, 2010 · Reply

  53. Hiren Khambhayta Author Editor

    Nice one, have used it in my website, its really speed boosting.

    September 22, 2010 · Reply

  54. Chris Author Editor

    First off, I’m sorry my bad English.
    I’ve a css sprites menu with other code and it is working on. My problem appear when I try to adapt it to WordPress 3.0.1 with a new function called wp_nav_menu().
    Basically my menu does not appear when I try to adapt my sprite. Are you trying to do it with yours?
    I hope you understand my English hehe, I’m sorry and thanks for this tutorial.
    Cheers!!

    October 11, 2010 · Reply

  55. rexusdiablos Author Editor

    Is there any chance at all that you’d be able to give me a few pointers on layer styles for the text in Photoshop. Any chance of a few metrics for the shadow of the white text and how you achieved the inset effect for the black text?

    October 11, 2010 · Reply

  56. rexusdiablos Author Editor

    Is the font Beba Neue by any chance?

    October 11, 2010 · Reply

  57. soma Author Editor

    Using filter alphaImageloader is a solution to our problems but filter does not have background positioning.Fortunatelly the belatedPng script comes to our rescue, saving the day.It uses vml to handle png -s and yes it can handle background-positioning.

    October 20, 2010 · Reply

  58. rory Author Editor

    very nice, I never knew you could do that. I have been using individual images for each navigation tab, but I may just change my ways. great post

    October 28, 2010 · Reply

  59. Stephen Webb Author Editor

    As someone who regularly uses sprites in their work I can see this is a great introduction into the technique.

    I’ve never seen the ‘selected’ class used before so I’ll be incorporating this into my workflow next time I have to develop a sprite menu.

    Great graphics here, I particularly like the usage of subtle drop shadows and textures!

    October 29, 2010 · Reply

  60. Douglas Author Editor

    For those of you who are tired of constantly updating sprites, check out this new php css sprite generator. It automatically produces an optimized sprite, allows custom configuration and automatically adds the offsets to your css declarations.

    http://www.SpriteMeister.com

    November 21, 2010 · Reply

  61. eric Author Editor

    thanks for this tutorial, I’ve successfully tried this tap menu.
    This turorial is useful to me and now I will try to change color
    in accordance with the character of my blog,
    regard

    December 22, 2010 · Reply

  62. Liminal Design Cornwall Author Editor

    Nice tutorial, going to give it a go for the new studio site we are developing. Also thanks to Douglas for the link – very handy! Thanks.

    Ryan

    December 31, 2010 · Reply

  63. bill Author Editor

    awesome dude saved me a lot of headache thanks :)

    January 23, 2011 · Reply

  64. jokonardi Author Editor

    great job….i like jquery menu …
    thanks…

    January 31, 2011 · Reply

  65. daniel Author Editor

    I need to style a list generated in Drupal. The distinguishing classes are added to the link tag. How would you rephrase the syntax to reference the classes there?

    February 1, 2011 · Reply

    • daniel Author Editor

      okay. I was able to bump my distinguishing classes to the li tags. But the ul tag has no id and a class=”menu”. I changed all the hash symbols to dots, but it has no effect on the list. Recommendations?

      February 1, 2011 · Reply

      • daniel Author Editor

        Got it. Thanks for the tutorial.

        February 4, 2011 ·

  66. Lasha williams Author Editor

    awesometutorial. i like :love: ` thanks : )

    February 4, 2011 · Reply

  67. Ali Author Editor

    I can’t find the link to the .Zip file. Can anyone post it here?
    Thanks!

    February 7, 2011 · Reply

  68. Mustafa Author Editor

    thank u very muchh

    February 10, 2011 · Reply

  69. web design manchester Author Editor

    The menu uses sprites .. can anyone suggest a good sprite generator as its easy i guess … but will say this tutorial has given me good advice about menus. Thanks

    February 28, 2011 · Reply

  70. Eddie Author Editor

    [quote]can anyone suggest a good sprite generator[/quote]

    See spriteme.org it does it to your site.

    March 2, 2011 · Reply

  71. Eddie Author Editor

    [quote]I can’t find the link to the .Zip file[/quote]
    Look for the download button below his picture.

    March 2, 2011 · Reply

  72. Simon Author Editor

    Hi thanks for this tutorial. It seems to work really good. I’m going to use it on my site for my social links roller over buttons. I also love the menu idea you’ve shown, I might seek “inspiration” from it one day ;) Also the part about turning the rulers on in photoshop was a big help!! Duh, I should have thought of that one earlier, but makes things a LOT easier :)
    haha, Cheers! Simon.

    March 2, 2011 · Reply

  73. oren Author Editor

    hi.
    thank you for this tutorial.
    i do have one problem – when i mouse-over on the tab of the current active page, the hover effect works. i want it to work only for the other tabs and not for the active one.
    how can i do that ?
    thanks again :)
    oren

    March 12, 2011 · Reply

  74. John Author Editor

    Hey Oren,

    Did you figure out your ‘hover’ issue?

    thanks….

    March 23, 2011 · Reply

  75. Joey Author Editor

    Could someone please be so kind on explaining how to integrate some jQuery to make it fade in/out or ‘ease’ some how? Also achieved by unitising a search engine friendly method.

    Many thanks

    March 29, 2011 · Reply

  76. omar Author Editor

    thank you tis very useful

    April 2, 2011 · Reply

  77. cryoffalcon Author Editor

    thanks for sharing this information it is really helpful. And i wanted to use sprites from long time.
    take care.

    April 5, 2011 · Reply

  78. Joey Author Editor

    Could someone please be so kind to explaining how to integrate some jQuery to make it fade in/out (easing) some how? Also achieved by utilising a search engine friendly method.

    Many thanks

    April 6, 2011 · Reply

  79. Artyom Shmatok Author Editor

    That that is necessary for me.
    Thanks!

    April 13, 2011 · Reply

  80. arifur rahman Author Editor

    here is a nice article about css sprites.

    http://learneveryday.net/css/css-sprites-for-website-performance/

    April 24, 2011 · Reply

  81. Punyada Author Editor

    thanks nice tutorial..

    June 2, 2011 · Reply

  82. Adam Author Editor

    I have a lot of small elements [like the blockquote start + end and other things ] that the google speed test recommened to be piled into a sprite. Am thinking of implementing it soon since you made the tut look so easy. Thank you so much!

    June 16, 2011 · Reply

  83. Dbarlok Author Editor

    Thanks for this!

    August 1, 2011 · Reply

  84. Ally Author Editor

    Great tutorial! I was studying another tutorial that did the same thing but the CSS code here is, to a complete beginner like me, way cleaner, better organized and a lot easier to understand.

    August 16, 2011 · Reply

  85. Diego Author Editor

    All yuor tutorials are interesting. I would like you to put a demo of them

    August 17, 2011 · Reply

  86. sam Author Editor

    I found nice article for CSS code.Thanks for sharing this important article. Currently i am facing issue with me web site.My web site taking lots of time for loading.If you have any important tips please share with me.

    Thanks,
    Sam

    September 15, 2011 · Reply

  87. BillyJr Author Editor

    Hi, Thanks for graet tutorial, but could you telle me how .selected class is changed? Do I need JavaScript to use it, because it doesn’t work on my site?

    September 28, 2011 · Reply

  88. KB Author Editor

    Another cool implementation of CSS sprite: Dynamic CSS Sprite implementation to give a painting effect. Read how to implement it by reading an easy to follow tutorial at
    http://blog.kunals.com/dynamic-css-sprite-implementation-gives-a-painting-effect/

    October 13, 2011 · Reply

  89. Kisstopher Author Editor

    Where is the zipped source code file?

    October 20, 2011 · Reply

  90. tarakbr Author Editor

    Hi! nice tutorial but providing the mentioned zipped file would be great; i have problems implementing it and i am sure the zipped file will help. Thanks in advance.

    October 22, 2011 · Reply

  91. HaMiD Fadaei Author Editor

    Very Useful

    Thanks

    :D

    You OK

    November 3, 2011 · Reply

  92. mahsa Author Editor

    hiiiii zach
    thanks alot!!!!

    November 7, 2011 · Reply

  93. Neil Gee Author Editor

    Thanks for this! works great

    November 11, 2011 · Reply

  94. Juve Colunga Author Editor

    Thanks a lot, too comprehencive tut

    November 18, 2011 · Reply

  95. Toni Author Editor

    I’m following you so far and it has been relatively easy once I got over the learning curve. I’m puzzled though as to where these coordinates come from:

    #menu li.home a{background-position:-5px -5px;}
    #menu li.home a:hover{background-position:-5px -75px;}
    #menu li.home a.selected{background-position:-5px -145px;}

    I have all of my width and heights for my three states but I just don’t know how to do the background position. Help! Please. Thanks.

    December 10, 2011 · Reply

    • Ryan Johnson Author Editor

      Hey Toni, the those positions come from what you see under the “Love the Grid” section. Put it this way:

      > Your height and width are like a square hole in a piece of paper.
      > The sprite is like another piece of paper with a bunch of images. While you have a bunch of images, you can only see whatever through that hole on the top piece of paper (height/width).
      > The overflow:hidden is what hides the rest of the sprite paper except for what can be seen through that hole.
      > Background-position basically shifts the sprite piece of paper around to display the desired sprite image you want to snugly display.

      That’s just how I imagine it, but hopefully it helps!

      January 27, 2012 · Reply

  96. Arjun Rajiv Author Editor

    Thanks a lot, great tutorial…..

    January 20, 2012 · Reply

  97. Candice Author Editor

    Marriage makes or mars a man.

    February 11, 2012 · Reply

  98. lv wallet Author Editor

    In 1909, louis vuitton purse family used silk and wool to make “Kashmir” travel blanket, which became the pioneer of scarf and quilt cover.

    March 17, 2012 · Reply

  99. AgepeCen Author Editor

    view beats by dre suprisely

    March 24, 2012 · Reply

  100. iannelsonks Author Editor

    Really good write-up and actually helps with comprehending the article much better.
    My partner and I were sent here seeing as this particular post has been tweeted by a guy I was following and am delighted I made it here. [url=http://santiagohens82.xanga.com/759878207/with-these-home-improvement-tips-bob-the-builder-will-have-absolutely-nothing-on-you/]haircut Coupons for you[/url]
    [url=http://michelmccall5113606.blog.hr/2012/03/1630307037/big-home-improvement-jobs-should-be-done-by-professionals.html]Promotional codes,Printable Swiffer Wet Jet coupons, and discounts[/url]

    I have to point out you put together several fine points and will probably write-up a a small number of options to add on as soon as a day or two.

    March 24, 2012 · Reply

  101. hakan yıldız Author Editor

    Thanks for , real helpful. I have only used this

    May 6, 2012 · Reply

 

Join the Conversation

Back to Top / Comment RSS

2012 Build Internet. Created by One Mighty Roar. Icons by Komodo Media. Back to Top