【问题标题】:Is there a way to scale background-image style?有没有办法缩放背景图像样式?
【发布时间】:2011-03-08 17:57:16
【问题描述】:

如果我将常规的img标签放在html中,我基本上可以指定宽度和高度,浏览器会缩放图像。只要尺寸与原始尺寸相差不大,结果就不错。

例如,头像图像被缩放到 32x32,即使原始图像是 45x45

<img width="32" height="32" alt="" src="http://www.google.com/friendconnect/scs/images/NoPictureDark.png">

有没有办法像这样缩放css背景图像中的图像?

<div class='avatar' style='background-image:url("hhttp://www.google.com/friendconnect/scs/images/NoPictureDark.png");'>

我基本上想将头像显示为背景图像的属性而不是通常的 img 标签,并且还需要将其缩放到大小。

有没有已知的技巧可以做到这一点?

【问题讨论】:

标签: html css


【解决方案1】:

这只能在 CSS3 中使用 background-size 属性实现。请参阅speccompatibility table

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 2012-07-08
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多