我如何调整大小和大小?通过 CSS 3 放大图像(如精灵图标)?
亲爱的朋友们。 想象一个名为 icons.png
的精灵图像,分配给带有各种 10x10px 图形的 css 类 .icons
。现在您需要另一个类,将精灵图形放大两倍 200%(使它们在屏幕上为 20x20 像素)
如何在 CSS 中纯粹实现这种放大?
非常感谢!
.icons, .iconsbig{ /* WORKS FINE */
background-image:url(http://site.org/icons.png);
background-repeat:no-repeat;
vertical-align: middle;
display: block;
height:10px;
}
.iconsbig{ /* make this one twice as big as the original sprite */
background-repeat:no-repeat;
height:20px;
background-size: 20px auto;
image-rendering:-moz-crisp-edges;
-ms-interpolation-mode:nearest-neighbor;
}
更新:
上述代码的问题:
- 它可以在 IE9 中运行,但不能在 FireFox 中运行,大多数使用的浏览器不知道如何调整大小???
- 在 IE9 中,放大效果很脏,而且邻居像素根本不完美?
Dear folks.
Imagine a sprite image called icons.png
assigned to css class .icons
with various 10x10px graphs. Now you want another class which scales up the sprite graphics exactly twice 200% (making them 20x20 pixels on the screen)
How do I achieve this enlargement purely in CSS?
Much appreciated!
.icons, .iconsbig{ /* WORKS FINE */
background-image:url(http://site.org/icons.png);
background-repeat:no-repeat;
vertical-align: middle;
display: block;
height:10px;
}
.iconsbig{ /* make this one twice as big as the original sprite */
background-repeat:no-repeat;
height:20px;
background-size: 20px auto;
image-rendering:-moz-crisp-edges;
-ms-interpolation-mode:nearest-neighbor;
}
update:
problems with the above code:
- It works in IE9, but not in FireFox, by most used browser doesnt know how to resize????
- in IE9, the enlargement is smudgy and not neithrest neighbour pixel perfect at all??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了 几乎所有内容都支持,除了 IE9...
W3C 规范。
更新
看起来 Firefox 希望在财产。
It is supported in pretty much everything except for < IE9...
W3C spec.
Update
Looks like Firefox wants its vendor prefix (
-moz
) on the property.您可以使用 css3
background-size
属性:You can use the css3
background-size
property: