html - 宽度为 % 的 div 中的 Css sprite?

标签 html css css-sprites liquid-layout

是否可以在 div 中使用 width % 的 Css sprite 图像?

现在我尝试了这个但不起作用:

.sprite-gloss-vulc {
    background-image: url("/images/sprite-img.png");
}

.sprite-gloss-vulc-anello { 
  background-position: -1px -0px; 
  width: 120px; 
  height: 120px; 
}

#flex {
 width: 17%;
}

img {
  width: 120px; 
  height: 120px; 
}


<div id="flex">
    <img src="/images/transparent.gif" class="sprite-gloss-vulc sprite-gloss-vulc-anello">
</div>

当 div parent 的宽度大于 120px (width img) 时有效,但如果我调整页面大小,css sprite 将被“剪切”。 被剪掉是因为 div 的新闻宽度变小了,但是大小 .sprite-gloss-vulc-anello 它们仍然是一样的。

我希望你能原谅我的英语并帮助我...... 非常感谢!

最佳答案

你给 img 标签和类 height width 和 twice

.sprite-gloss-vulc {
    background-image: url("/images/sprite-img.png");
}

.sprite-gloss-vulc-anello { 
  background-position: -1px -0px; 
  width: 100%; 
  height: 100%; 
}

#flex {
 width: 100%;
}

关于html - 宽度为 % 的 div 中的 Css sprite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39722168/

相关文章:

css - 从 Sprite 中获取图像并将其放入 <td> 标签中

css - SASS + COMPASS - 图像 Sprite 重复-y

css - 仅对颜色使用背景重复的缺点?

html - 映射onclick禁用父div的滚动条

html - 制作父级包含列的 Bootstrap 导航栏宽度

html - 用图案填充 SVG 路径而不拉伸(stretch)

jQuery - 选项卡 - 需要一点帮助/指导

html - Css 如何在一行中设置 3 个 block block /div

html - CSS:在另一个 float 列下 float 一个列

javascript - 根据菜单选择显示/隐藏表单输入字段