IT俱乐部 HTML5 HTML5 body设置全屏背景图片的示例代码

HTML5 body设置全屏背景图片的示例代码

用什么代码实现?不允许有白色底色产生,因为手机高度不一样

设计图要标准(750)确认是背景图(通屏底图)应用场景:移动端宣传页面或者活动页面

错误的写法:加到div中结合图片设置min-height,但是页面不会回弹

终极方案

1
2
3
4
html,body{
    width:100%;
    height:100%
}
1
2
3
4
5
body{
  font-family: "华文细黑";
  background:url("../img/Flyer-bg.png") no-repeat;
  background-size: 100%;
}

一个hack方案解决垂直剧中问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<title>缓存</title>
    .parent{
        width:200px;
        height: 200px;
        /* 以下属性垂直居中 */
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        background-color: #aaa;
    }
<div class="parent">111</div>

其他方案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    <title>Document</title><div id="Layer1" style="position:fixed;left:0px;top:0px;width:100%;height:100%"
    <img decoding="async" src="https://www.qianbuxian.com/uploads/banners/20171214085954_shouye5.jpg" width="100%" height="100%">
</div>
<p>清除浮动</p>
<div class="jb51code">
<pre class="brush:xhtml;">.float-left {
    float: left;
}
.float-right {
    float: right;
}
.clear-fix:after {
    display: table;
    content: '';
    clear: both;
}</pre>
</div>
<p>到此这篇关于HTML5 body设置全屏背景图片的示例代码的文章就介绍到这了,更多相关html5 body背景图片自适应屏内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章,希望大家以后多多支持IT俱乐部!</p>
<div class="clearfix">
                        <span id="art_bot" class="jbTestPos"></span>
                        </div>

相关文章

最新评论

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/navsub/html5/13635.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部