css - 固定背景调整到显示器尺寸

标签 css background background-image

你能告诉我如何让背景图像适应显示器的大小吗? 这是我得到的:

body {
background: url(../images/bg.jpg) #eee fixed no-repeat center;
-webkit-background-size: cover;
   -moz-background-size: cover;
     -o-background-size: cover;
        background-size: cover;
font: 12px Tahoma, sans-serif;

即使我在一台显示器上有垂直滚动条而在另一台显示器上没有滚动条。

谢谢!

最佳答案

固定居中的背景

background: url(images/bg.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;

工作于:

Safari 3+
Chrome Whatever+
IE 9+
Opera 10+ (Opera 9.5 supported background-size but not the keywords)
Firefox 3.6+ (Firefox 4 supports non-vendor prefixed version)

关于css - 固定背景调整到显示器尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30753010/

相关文章:

html - 尽管没有内容,但使容器 100% 高度

android - 在 Android 应用程序中重复背景横幅

android - Android 中的 GridView 行背景图片

javascript - 带有动态图像的手动 JavaScript 幻灯片放映

jquery - 用边框替换的水平规则

html - 我可以只为 div 的背景图像设置不透明度吗?

android - Activity 背景模糊,不知道后面是什么 Activity

html - 在 CSS 中将 anchor 应用于背景图像

html - 在没有文本的情况下向 div 添加背景?

html - 从样式表和 html 自定义背景