带内联图像的精灵

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带内联图像的精灵相关的知识,希望对你有一定的参考价值。

  1. // Generically
  2.  
  3. <img src="images/arrow-sprite.png" alt="arrow" class="clip pos-1" />
  4.  
  5. .clip { position: absolute; top: 0; left: 0; }
  6.  
  7. .pos-1 { clip:rect(0 48px 48px 0); }
  8. .pos-2 { clip:rect(0 96px 48px 48px); left: -48px; }
  9. .pos-3 { clip:rect(48px 48px 96px 0); top: -48px; }
  10. .pos-4 { clip:rect(48px 96px 96px 48px); top: -48px; left: -48px; }
  11.  
  12.  
  13. // Within Flow
  14. // Use the same CSS as above, only wrap the image in a div with relative positioning and a matching height and width to the area you want to show.
  15.  
  16. <div class="clipwrapper">
  17. <img src="images/arrow-sprite.png" alt="arrow" class="clip pos-1" />
  18. </div>
  19.  
  20. .clipwrapper { position: relative; height: 48px; width: 48px; }
  21.  
  22.  
  23. /*
  24. Points to remember
  25.  
  26. * The element needs to be absolutely positioned.
  27. * To use it on an element and keep document flow, using a wrapping div with a relative position.
  28. * The clipped away areas are transparent but still occupy space.
  29. * For sprites other than the top/left sprite, you'll need to nudge the position back the same top/left distance you clipped away.
  30. */

以上是关于带内联图像的精灵的主要内容,如果未能解决你的问题,请参考以下文章

如何识别非规则精灵图像的触摸?

在 Unity 5 中,为啥精灵表中的某些精灵在精灵中不可见,但在 UI 图像中可以正常工作?

分解精灵图像的简单工具? [关闭]

纹理包装动画图像/精灵表有效-Libgdx

将剪切图像之一分配给精灵渲染器

如何为所有精灵图像设置动画?