是否可以用CSS设置背景图像的大小?

我想做的事情是:

background: url('bg.gif') top repeat-y;
background-size: 490px;

但这样做似乎是完全错误的……


当前回答

put the below code in the body of you css file

background-image: URL('../images/wave-green-plain-colour.jpg') ;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
width:100px;

其他回答

只需有嵌套的div跨浏览器兼容

   
      <div>
         <div style="background: url('bg.gif') top repeat-y;min-width:490px;">
            Put content here
         </div>
      </div>
   

你写过

background: url('bg.gif') top repeat-y;    
background-size: 490px;

但是你只能看到背景,这取决于容器的大小。

如果你有一个带有background url和background-size的空容器,你将看不到bg.gif。

如果你将容器的大小设置为

background: url('bg.gif') top repeat-y;    
background-size: 490px;
height: 490px;
width: 490px;

结合上面编写的代码,您将能够看到bg.gif文件。

您无法使用当前版本的CSS(2.1)设置背景图像的大小。

您只能设置:位置,固定,图像-url,重复模式和颜色。

在CSS3中使用background-size可以做到这一点

.backgroungImage {
    background: url('../imageS/background.jpg') no-repeat;
    background-size: 32px 32px;
}
put the below code in the body of you css file

background-image: URL('../images/wave-green-plain-colour.jpg') ;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
width:100px;