code_junkie

Can't get CSS Sprite to work..what am I doing wrong?

Nov 13th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. .sprite-welcom1 { background-position: 0 -30px; }
  2. .sprite-welcom3 { background-position: 0 -109px; }
  3. .sprite-3 { background-position: 0 -188px; }
  4.  
  5. <html>
  6. <head>
  7. <style>
  8. .sprite-welcom1 { background-position: 0 -30px; }
  9. .sprite-welcom3 { background-position: 0 -109px; }
  10. .sprite-3 { background-position: 0 -188px; }
  11.  
  12. .sprite-bg {
  13. background: url(csg-495a902b04181.png) no-repeat top left;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div class="sprite-bg sprite-3"></div>
  19. </body>
  20. </html>
  21.  
  22. <html>
  23. <head>
  24. <style>
  25. .sprite-container div {
  26. background: url(csg-495a902b04181.png) top left no-repeat;
  27. width: 20px; //width is neccessary
  28. height: 20px; //height is neccessary
  29. }
  30.  
  31. .sprite-3 { background-position: 0 -188px; }
  32. .sprite-4 { background-position: -20px -188px; }
  33.  
  34. </style>
  35. </head>
  36. <body>
  37. <div class="sprite-container">
  38. <div class="sprite-3"></div>
  39. <div class="sprite-4"></div>
  40. </div>
  41. </body>
  42. </html>
  43.  
  44. .sprite-bg {
  45. background: url(csg-495a902b04181.png) no-repeat top left;
  46. width: 100px; /* (or whatever the width should be) */
  47. height: 100px; /* (or whatever the height should be) */
  48. }
  49.  
  50. /* Bad */ .childClass2 { background-position: -10px -20px; }
  51. /* Good */ .parentClass1 .childClass2 { background-position: -10px -20px; }
  52.  
  53. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  54. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  55.  
  56. <HTML xmlns="http://www.w3.org/1999/xhtml">
  57. <head>
  58. <style type="text/css">
  59. .sprite-container div {
  60. background: transparent url(//www.yourDomain.com/csg-495a902b04181.png) no-repeat scroll 0 0;
  61. width: 200px; /* width is necessary */
  62. height: 20px; /* height is necessary */
  63. }
  64. .sprite-container .sprite-3 { background-position: 0 -188px; }
  65. .sprite-container .sprite-4 { background-position: -20px -188px; }
  66. </style>
  67. </head>
  68. <body>
  69. <div class="sprite-container">
  70. <div class="sprite-3"></div>
  71. <div class="sprite-4"></div>
  72. <!-- Empty divs are fine! Unless you *really* want text on top of
  73. your sprite map. :o) Btw: &shy; is invisible when a hyperlink
  74. is wrapped around it. &nbsp is not... it creates an
  75. underscored hyperlink. Use &shy; which is a soft-hyphen.
  76. -->
  77. </div>
  78. </body>
  79. </html>
Add Comment
Please, Sign In to add comment