html5怎么设置整页背景图片

html-css07

html5怎么设置整页背景图片,第1张

html5加背景图片可以通过:

1.首先可以去写一个div,然后这个div当然宽高是一定要有,然后在div中去设置要的背景图片,是否重复等属性,repaet这个来设置,no-repeat(是不重复)、repeat-x(沿着x轴重复)、repeat-y(沿着Y轴重复)这里我提交一段代码:

<div id = 'test'></div>

<style>

#test{

width:300px

height:400px

background:url('图片的地址')no-repeat

}

</style>

这样背景图片就设置好了!

body{      font-family: "微软雅黑"

width: 100%

height:auto

background:url("../img/....png") no-repeat

background-size: 100%  }

在插入背景图片的容器里设置background-size: 100%,这样图片就会覆盖整页。

1,输入position:fixed;top:0;left:0;将整个div固定在屏幕的顶部和左侧。

2、输入width:100%;height:100%;min-width:1000px;这个可以适合div的高度和宽度,而min-width是为了实现让屏幕宽度在1000px以内时,div的大小保持不变。

3、输入background-size: cover-webkit-background-size: cover-o-background-size: cover使图片随屏幕大小同步缩放,但是有部分可能会被裁切,不过不至于会露白,下面两句是为chrome和opera浏览器作兼容。

4、输入background-position:center0;使图片的位置,居中,靠左对齐。