您现在的位置:首页 >> 前端 >> 内容

设置div水平垂直居中方法

时间:2016/12/20 9:21:00 点击:

  核心提示:margin: auto;position: absolute;top:0; left:0; bottom: 0; right: 0;这个方法是把margin设为auto,正常情况margin是0。当...

margin: auto;

position: absolute;

top:0; left:0; bottom: 0; right: 0;

这个方法是把margin设为auto,正常情况margin是0。
当绝对定位时,为了满足l,r,b,t都为0,margin被拉伸而且上下左右相等所以居中。
当l=0被取消时,container直接位置右移就能满足r=0,并不需要拉伸margin,所以左右margin默认为0。

Tags:设置 置D DI IV 
作者:网络 来源:westdu的博客
  • 上一篇:核心函数$()
  • 下一篇:[09]表单元素(下)