html - 制作全屏图像背景

标签 html css

我基本上想制作一个完整的视口(viewport)背景图像。

这是我的代码:

<html>
    <body>
        <div class="container">
        <img src="loginBg.png" height="100%" width="100%">  
    </div>
</html>

样式表如下:

.container{
    position:absolute;
    top:0px;
    bottom:0px;
    right:0px;
    left:0px;
}

这种方法的问题是,图像是全屏的,但它下面有一些空间,因为这个空间页面是可滚动的。我在 firefox ubuntu 上查了下,没有空白。

提前致谢

最佳答案

真正的解决方案——CSS背景图片

结合 no-repeatbackground-size 在主体上使用 CSS 背景图片。

2个例子

background-size: cover保持高宽比

body {
    background: url(http://www.placehold.it/200) no-repeat;
    background-size: cover;
}

使用 background-size: 100% 100% 拉伸(stretch)

注意:html,body { height: 100% } 允许百分比背景大小。

html,body {
  height: 100%;
}

body {
  background: #F00 url(http://www.placehold.it/200) no-repeat;
  background-size: 100% 100%;
}

阅读更多:

关于html - 制作全屏图像背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26194177/

相关文章:

html - 在 HTML 中,哪个元素不能包含其他一些特定元素?

html - 两个 div 在 html 和 CSS 中没有水平对齐

jquery - 单击全屏图库

css - 使用 Stylus 动态设置悬停背景

html - 在页面上定位图像 (HTML)

html - div不 float 到顶部

html - 在网站上使用自定义 .ttf 字体

html - 如何通过Delphi 7通过Outlook发送带有表格的电子邮件

html - 不同元素的悬停效果不起作用

javascript - 如何让我的汉堡包导航图标正确转换?