请问怎么让div中的div在垂直方向上居中呢?

比如:下面这段代码,如何让里面的div在垂直方向上面居中呢(不好意思,实在是没有悬赏币了)

.out{ width:500px; height:500px; background:blue; } .inn{ width:200px; height:200px; background:red; }

你的inn怎么比out还大。。搞反了吧。。通过margin来定位。absolute定位最好,不需要考虑父容器,只需要依据自身的宽和高度来调整margin

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<style>.out{  width:300px; height:300px; background:blue; position:relative} .inn{ width:200px; height:200px;background:red;position:absolute;margin-left:-100px;margin-top:-100px;left:50%;top:50% } </style>
<div class="out"><div class="inn"></div></div>

固定高度的话可以用margin-top

可以通过margin-(top/right/botton/left)进行排版和定位,最好是用百分比进行调试。