我有以下简单的代码:

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html  ns=\"http://www.w3.org/1999/xhtml\"  :lang=\"en\">

<head>
  < >Live Feed</ >

  <  http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />

  <style>
    body {
      margin: 0px;
      padding: 0px;
    }
  </style>
</head>

<body>
  <div style=\"background-color: #eeeeee; width: 250px; height: 100%; border-right: solid 1px #e1e1e1;\">
    I should be tall
  </div>
</body>

</html>

可div并没有按照所想的那样展开,但将div设置固定高度时能够正常展开,这是什么原因? 

因为在给元素设置百分比高度时要制定父布局高度,在这里我们需要设置body和HTML的高度。 真确代码如下:

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html  ns=\"http://www.w3.org/1999/xhtml\"  :lang=\"en\">

<head>
  < >Live Feed</ >

  <  http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />

  <style>
    body {
      margin: 0px;
      padding: 0px;
      height:100%;
    }
    html{
      height:100%;
    }
  </style>
</head>

<body>
  <div style=\"background-color: #eeeeee; width: 250px; height: 100%; border-right: solid 1px #e1e1e1;\">
    I should be tall
  </div>
</body>

</html>
收藏 打印