注轉載: http://www.noobyard.com/article/p-nevsunbq-hu.html
結果:
這個方法使用了一個 position:absolute,有固定寬度和高度的 div。這個 div 被設置爲 top:0; bottom:0;。但是因爲它有固定高度,其實並不能和上下都間距爲 0,因此 margin:auto; 會使它居中。使用 margin:auto;使塊級元素垂直居中是很簡單的。
原轉載有一個有點問題,還有一個沒實現,又加了一個別人實現的。
關於display:flex的知識,看阮一峯的官網:
http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html