保证金:自动自动

时间:2012-10-10 19:21:03

标签: css centering

  

可能重复:
  Why don't margin-top: auto and margin-bottom:auto work the same as their left and right counterparts?
  What is the rationale behind margin-top: auto and margin-bottom: auto amounting to 0 margin?

为什么margin: auto auto;没有添加垂直居中? auto关键字不应该告诉浏览器在顶部和底部之间平均分割边距吗?我的印象是它对左右边缘的作用。

2 个答案:

答案 0 :(得分:4)

最终它是一个w3c规范 -

  

如果'margin-top'或'margin-bottom'为'auto',则其使用值为0.

看起来确实很方便。

答案 1 :(得分:0)

auto关键字应该执行w3c spec中定义的任何内容,恰好是:

  

如果'margin-top'或'margin-bottom'为'auto',则其使用值为0.