2010-09-18 49 views
1

我必须缺少一些简单的东西......我试图创建一个图像设置为背景的html页面。现在,我希望图片占据页面的70%,并与右上角对齐。CSS问题:如何设置背景图像的宽度?

我能够将图像对齐到页面的右上角,它在Chrome中看起来很不错,但在IE中很糟糕。在IE中,图像占据了整个页面 - 这种情感上会破坏页面的外观和感觉...

有什么我失踪了吗?如何限制IE中背景图片的大小?有什么想法吗?下面的代码:

<html> 
<head> 
<style type="text/css"> 
    body { 
     margin: 0; 
     background: transparent url(Background2.png) no-repeat fixed right; 
     background-position: right top; 
     font-size:12px; 
    } 
</style> 
</head> 
<body> 
    Hello! 
</body> 

回答

1

这是一个CSS3功能并且只有在最新的浏览器支持。 Mozilla在Firefox 3.6中引入了这个功能,当Webkit/Chrome没有时,我不会起诉。

-moz-background-size: 300px; 
-webkit-background-size: 300px; 
background-size: 300px; 

你可以找到一个Mozilla文档here

0

宽度CSS3,你可以做到以下几点:

body { 
background: url(bgimage.jpg) no-repeat; 
background-size: 100%; 
} 

其他你应该使用一些技巧,因为它是描述here。 最好的方式提到的有:

#img.source-image { 
    width: 100%; 
    position: absolute; 
    top: 0; 
    left: 0; 
} 

另一个假的解决方案是here