这个最好定宽,定高,如果自适应那么就需要要js来进行控制了.假如div宽200px,高100px,那么居中样式就是这样:position:fixed;top:50%;left:50%;margin-top:-50px;margin-left:-110px;这样就居中了,如果是自适应,需要使用js获取div的宽度和高度,然后将margin-top:-高度/2像素,同理,margin-left设置-宽度/2像素.
div{position:fixed;margin:auto;left:0; right:0; top:0; bottom:0;width:200px; height:150px;}
<pre t="code" l="html"><style>#center{width:50px;height:50px;background-color:red;position:fixed;top:50%;left:50%;margin-left:-25px; /* width的一版半的相反权数 */margin-top:-25px; /* height的一半的相反数 */z-index:999;}</style><div id="center"></div>
CSS实现水平和垂直居中要让DIV水平和垂直居中,必需知道该DIV得宽度和高度,然后设置位置为绝对位置,距离页面窗口左边框和上边框的距离设置为50%,这个50%就是指页面窗口的宽度和高度的50%,最后将该DIV分别左移和上移,左移
.0000000
弹出层吗?写完需要弹出的页面后position设置为fixed;样式为display:none;用js或jquery控制点击事件,移除或添加display:none;属性
方法很多,一般而言是用align="center",另外还可以微调(不过不建议你用).你把你的页面代码给出来吧,我直接更改,你可以直接用,这样方便不明白请追问,如果对你有帮助,记得采纳~
text-align:center 写上这个属性 再看看别人怎么说的.
jQuery如何将div设置为水平垂直居中:使用CSS也可以实现div的水平垂直居中效果,但是有时候可能需要动态的调整,下面就介绍一下如何用jQuery实现对象的水平垂直居中效果,先看一段代码实例:<!DOCTYPE html><html><head><meta
123456789101112131415 <styletype="text/css">.layer { positon:absolute; left:50%; top:50%; width:300px; height:200px; margin-left:-150px; margin-top:-100px; background:#000; opacity:0.8; filter:Alpha(opacity=80); }</style><divclass="layer"></div>