如何设置主 div 的中心?我会尝试很多方法,但我做不到。左、右看起来都还好。如何更改垂直位置属性?我尝试过这些:
margin-left:auto;
margin-right:auto;
margin-top:auto;
margin-bottom:auto;
vertical-align:middle;
这些不起作用。
#main
{
width:1024px;
height:600px;
position:relative;
z-index:1;
margin:auto auto;
text-align: center;
}
最佳答案
工作示例(使用下面教程的方法 2):http://jsfiddle.net/heAXR/1/
这是一个很好的教程,它展示了几种垂直居中内容的方法: http://blog.themeforest.net/tutorials/vertical-centering-with-css/
我很喜欢文章中描述的方法 3,这里有一个演示: http://douglasheriot.com/tutorials/css_vertical_centre/demo5.html
关于css - Div垂直对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12834748/