2016-01-20 82 views
0

我需要调整背景“Image.png”的大小为112 x 22像素,但是当我修改widthheight时,它会将图像裁剪为所提供的大小而不是调整大小。
我如何调整大小在CSS中的图像?在CSS中调整背景图片大小

#Title-1 { 
    width: 148px; 
    height: 29px; 
    margin-left: 10px; 
    background-image: url("/pic/Image.png"); 
    display: inline-block; 
    vertical-align: top; 
} 
+0

因为您使用图像作为** CSS背景**,而不是内嵌图像(''),请参阅[此参考答案](http://stackoverflow.com/questions/376253/stretch-and-scale-css-background)和CSS属性'background-size'。 –

+0

可能重复[调整图像与CSS成比例?](http://stackoverflow.com/questions/787839/resize-image-proportionally-with-css) –

回答

0

这是因为当你修改widthheight值,你实际上是在改变这些值的容器。

你会想要将它添加到您的CSS:

#Title-1 { 
    background-size: 112px 22px; 
    background-repeat: no-repeat; 
} 
+0

好吧,我现在明白了。 –

0

您是否试过background-size选项?

background-size: 112px 22px; 
0

我现在就买下,

我用解决它:

background-size:cover 

谢谢大家。