html - 我们如何定位从图像 Sprite 获得的图像?

标签 html css

问题是如何定位从图像 Sprite 获得的图像,因为背景位置属性已经用于从 Sprite 定位图像?例如,在下面的代码中,我如何才能在网页中的所需位置定位从 Sprite 获得的家。

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
  <style type="text/css">
  img.home
  {
   width:46px;
   height:44px;
   background:url(img_navsprites.gif) 0 0;
  }
  </style>
 </head>

 <body>
    <img class="home" src="img_trans.gif" width="1" height="1" />
 </body>
 </html>

其中,(img_trans.gif) 是透明图像,(img_navsprites.gif) 是图像 Sprite 。

最佳答案

您应该通过设置 position: absolute 并设置 topleft 来移动整个元素。

关于html - 我们如何定位从图像 Sprite 获得的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6721818/

相关文章:

javascript - jQuery/JS - 变量似乎没有更新?

javascript - v-for循环中的单选输入选择相同值的多个单选按钮

javascript - 当我将鼠标悬停在 iframe 上时,DIV 会闪烁

javascript - 将背景扩展到屏幕边缘

javascript - 交换文本标签以选择值

html - Ionic 2 float ionic 标签问题

jquery - 无法调整第二个背景空间的大小

javascript - 多个嵌套选项卡

css - SASS 定期将代码注释插入我编译的 CSS 中

html - 更改下拉菜单的宽度