用純css做置中效果

剛好看到有人分享的,就做一下筆記,沒有什麼高深的技術,這招學起來還算有用。

Demo

記得要用一層東西把div包起來,並把他的position設為relative就好了,然後在要置中的div寫這樣的css
  1. .Absolute-Center {   
  2.   width50%;   
  3.   height50%;   
  4.   overflowauto;   
  5.   marginauto;   
  6.   positionabsolute;   
  7.   top: 0; left: 0; bottom: 0; right: 0;   
  8. }  

還有其他的用法,可以參考這篇
Absolute Centering in CSS

留言