html - 背景图片没有覆盖整个屏幕

标签 html css background

我有一张尺寸为 1620*1080 的背景图片,屏幕分辨率为 1366*768。它怎么可能不覆盖我屏幕的大约 15%(右侧部分)?

这是我的代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body { 
    min-height: 100%;
    min-width: 100%;
    background-image:url(background.png);
    background-repeat: no-repeat;
}

div#container {
    margin: 0 auto;
    background-color: red;

}
</style>
</head>
<div id="container">

</div>
<body>
</body>
</html>

如你所见,我添加了

min-height: 100%;
min-width: 100%;

认为这可能会有所帮助。 background-repeat: no-repeat; 只是因为它没有覆盖屏幕。

有什么想法吗?谢谢!

最佳答案

试试这个:

body { 
    background: url(background.png) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

无论窗口比您的图像大还是小,这都会为您提供全尺寸背景图像。

如果这不起作用,请阅读 this css-tricks post 的其余部分.

关于html - 背景图片没有覆盖整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367403/

相关文章:

javascript - 如何使用 jQuery 从上到下移动一个 div?

html - 如何在CSS中制作倒三 Angular 形轮廓

html - 如何增加导航中菜单分隔符的高度?

html - 去除html中不必要的空白

javascript - 使用 jQuery 替换 li 标签内的文本

ios - iOS 应用程序保证在后台停留多长时间而不被从内存中删除?

c++ - 当我使用DirectWrite在GDI hdc上绘制文字时,如何设置透明背景?

php - 如何通过 .php 文件根据值的内容更改值的背景颜色?

html - Twitter 卡片预览无法获取我的图像

html - 将 div 居中到屏幕