Bug can at anywhere,Can you find it?
由css撰写的日志
最快捷的纯CSS的 DIV 垂直居中
八 5th
div 垂直居中这个话题搜索引擎一堆,方法也有好几种。下面介绍一种比较快捷的方法。
假如 box 的高和宽为100px
.centered_div { width: 100px; height: 100px; position: absolute; top: 50%; left: 50%; margin-left: -50px; margin-top: -50px; background: red; }
假如 box的宽度为500px 高度为200px
.centered_div { width:500px; height: 200px; position: absolute; top: 50%; left: 50%; margin-left: -250px; margin-top: -100px; background: red; }