背景图片怎么居中,css用哪个样式比较好?
background:url(图片地址) no-repeat center top
###楼上几种方法都可以试试!
###背景图片干嘛想做居中 直接铺满不行吗?
###楼上们说的很好,厉害
###一楼说的对
###学习下
###自己做网站优化吗 很厉害
###background:url(图片地址) no-repeat center top 这个就可以 但还需要看你的图片大小
###你是自己写代码么?以下供你参考
CSS背景图居中
横向居中:
background:url(图片地址) no-repeat center top
纵向居中:
background:url(图片地址) no-repeat left 50%
这里50%是随意设置考上为50%距离,细节具体上下垂直居中需要再通过百分比均衡设置。
==================
网页背景居中的方法有很多种的。这里介绍一些用CSS让背景图片居中的方法。
让背景图片居中的第一个方法是用像素设定,很多都用这种,但是也是最麻烦的:
<div style="width:800px;height:600px;background:url(../images/logo.jpg) no-repeat 250px 270px;border:1px solid #cccccc;"></div>
第二种居中方法:用50%设定,很方便:
<div style="width:800px;height:600px;background:url(../images/logo.jpg) no-repeat 50% 50%;border:1px solid #cccccc;"></div>
第三种:用center设定(第2个center可以省略)
<STYLE TYPE="text/css">
<!--
BODY {background-image: URL(../images/logo.jpg);
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;}
-->
</STYLE>
本文来自投稿,不代表微盟圈立场,如若转载,请注明出处:https://www.vm7.com/a/ask/82499.html