html - CSS 中的全屏响应式背景图片

标签 html css image background-image

我想制作this image作为我网页的背景图片。然而,问题是图像没有覆盖整个页面,正如您在 this preview 中看到的那样。 , 并在最右端重复。有没有办法让图像覆盖整个页面(无论是任何方式、拉伸(stretch)、调整大小或新的方式)。

我的代码:

<!DOCTYPE HTML>
<html>

    <head>
        <title>Angry Birds Star Wars</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <style>
            body {
                background: url('http://www.androidtapp.com/wp-content/uploads/2012/11/Angry-Birds-Star-Wars-Menu.png');
            }
        </style>
    </head>

    <body></body>

</html>

谢谢。

更新:

我现在终于开始相信,几乎没有任何东西可以让图像完全适合我的 PC 屏幕。我现在很好,并且正在更进一步,请不要现在发布答案。

最佳答案

jsBin demo

background: url(image.jpg) fixed 50%;
background-size: cover;                 /* PS: Use separately here cause of Safari bug */

fixed(背景附件)是可选的。


以上只是简写:

background-image      : url(image.jpg);
background-attachment : fixed;
background-position   : 50% 50%;     /* or: center center */
background-size       : cover;       /* CSS3 */

您可以在所有现代浏览器中但 Safari 使用:

background: url(image.jpg) fixed 50% / cover;

其中 / 用于后台速记以将 positionsize 分开和区分(因为 position 接受单个和多个 (X,Y) 值),但 Safari 对此 / 简写存在错误,因此请按上述方式使用。

关于html - CSS 中的全屏响应式背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50488746/

相关文章:

css - 提取主题感知样式的 CSS 差异

python - Flask 模板无法加载 css

css - 背景图片在线不显示,但在本地

iOS-图像未显示自定义单元格(Swift)

html - 导航栏点击在元素下

javascript - 在 jQuery 中使用 .fadeOut() 时禁用单击

html - 如何将一个字符替换为另一个字符但仅限于 href?

html - 提交按钮跨浏览器定位

android - 裁剪后设置 ImageView 不起作用

html - 影响图像显示方式的 href