下面的红色的div怎么垂直居中了
不要用margin-top那样来定位了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title></head><body>
<div style="height:300px; width:300px;  background-color:#0000FF">
<div style="height:100px; width:100px;margin:0 auto; background-color:#990000"></div>
</div>
</body>
</html>

解决方案 »

  1.   

    div中加入 align ="left"
    就能靠左了
      

  2.   

    “下面的红色的div怎么垂直居中了”
    你看清楚楼主的语气 看仔细再去评论别人
      

  3.   

    要居中 就加 align ="center"
    保险起见
      

  4.   

    align:center 是左右居中,不是垂直居中吧?
      

  5.   

    valign table才有这属性的吧?div有valign? 汗啊
      

  6.   

    呀 这样啊 我也没用过 一直以为能用的 那这么说 CSS的vertical-align 应该也不好使吧?
      

  7.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title></title></head><body>
    <div style="height:300px; width:300px;  background-color:#0000FF">
    <table border="0" cellpadding="0" cellspacing="0" ><tr><td width="100px">&nbsp;</td><td width="100px" valign="middle">
    <div style="height:100px; width:100px;margin:0 auto; background-color:#990000"></div>
    </td><td width="100px">&nbsp;</td></div>
    </body>
    </html>
      

  8.   


    <div style="height:300px;width:300px;background-color:#0000FF; text-align:center;vertical-align:middle;position: absolute;">
    <div style="height:100px;width:100px;background-color:#990000;position: absolute;top:expression((this.parentElement.offsetHeight-this.offsetHeight)/2);left:expression((this.parentElement.offsetWidth-this.offsetWidth)/2);">
      

  9.   

    <div style="height:300px; width:300px;  background-color:#0000FF"><table height="100%"><tr><td valign="middle">
    <div style="height:100px; width:100px;margin:0 auto; background-color:#990000"></div>
    </td></tr></table>
    </div>搞个table,感觉不是太好啊。