
background-position:center
这个值也可是数值,
可以有两个参数
第一个值是水平位置,第二个值是垂直位置。
左上角是 0% 0%。右下角是 100% 100%。
如果您仅规定了一个值,另一个值将是 50%。
具体见w3cschool,既然是学生,就去看一下,所学一些CSS使网页背景居中的三种方法。
1、第一种:用像素设定,很多都用这种,但是也是最麻烦的:
<div style="width:800px;height:600px;background:url(地址) no-repeat 250px 270px;border:1px solid #cccccc;"></div>
2、第二种:用50%设定,很方便。
<div style="width:800px;height:600px;background:url(地址) no-repeat 50% 50%;border:1px solid #cccccc;"></div>
3、第三种:用center设定(注:第2个center可以省略,因为默认就是center)。
<div style="width:800px;height:600px;background:url(地址) no-repeat center center;border:1px solid #cccccc;"></div>你可以这样做的,在body里做一个div,这个div是仅次于body的div,然后看你这张背景的宽度和高度,设好这个div的宽度和高度(等于背景的宽度和高度),最后把这张背景引入就好了。
如
这个div的css
div{
width:xxxpx;
height:xxxpx;
margin:0 auto;
background:url(地址);
}
如果你一定要在body下插入背景的话,可以这样试试
body{
background:url(地址) no-repeat top center;
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)