回复讨论(解决方案)
设置CSS:
div{
margin-left:auto;
margin-right:auto;
}
这个需要动态设置Div的位置
style="position:absolute;top={1}px;left={2}px;"
如上,你的Div的样式需要设置为这个,但top和left是需要动态计算的。
问题点就是要动态的获取浏览器窗口的尺寸。于是解决办法如下:
DIV居中显示 var setDivCenter = function(divId){ var oDiv = document.getElementById(divId); oDiv.style.position = "absolute"; oDiv.style.top = (document.body.offsetHeight - 150) / 2 + "px";//这个150是div的高度 oDiv.style.left = (document.body.offsetWidth - 200) / 2 + "px";//这个200是div的宽度 };我在浏览器的中间
查看更多关于Div在浏览器中居中显示_html/css_WEB-ITnose的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did104002