-1

我正在使用此代码来创建我的网站的布局。我的问题是“左”和“右” div 没有显示在屏幕上。(当我将它们的高度设置为像素而不是百分比时,它们会显示)我该怎么做才能显示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <style type="text/css" media="screen">
    * { 
        margin: 0; 
    }

    html, 
    body { 
        height: 100%; 
    }

    #wrapper {
        min-height: 100%;
        height:     auto !important;
        height:     100%;
        margin:     0 auto -44px; /* -44px being the size of the footer */
    }

    #header { 
        height: 86px; 
    }

    #footer, 
    #push {
        height: 44px;   
    }

    #left
    {
      width:8px;
      width:100%;
      background-color:blue;
      float:left;
    }


    #right
    {
      width:8px;
      width:100%;
      background-color:blue;
      float:right;
    }

    #left: first,
    #right: first,
    {
    content: "";
    height: 0;
    clear: both;
    display: block;
    }
    </style>
</head>
<body>
    <div id="wrapper">
        <div id="header">header</div>
        <div id="content">
         <div id="left"></div>
         content
         <div id="right"></div>
        </div>
        <div id="push"></div>
    </div>
    <div id="footer">footer</div>
</body>
</html>
4

2 回答 2

4

工作方式:

您需要更改这些类:

#content {height: 80%;}
#left, #right {width: 30%; height: 100%;}

我已经更新了下面的代码并发布了完整的文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <style type="text/css" media="screen">
    * { 
        margin: 0; 
    }

  html, 
  body { 
      height: 100%; 
  }

  #wrapper {
      min-height: 100%;
      height:     100%;
      margin:     0 auto -44px; /* -44px being the size of the footer */
  }

  #header { 
      height: 86px; 
  }

  #footer, 
  #push {
      height: 44px;   
  }

  #left
  {
    width:8px;
    width:30%;
    background-color:blue;
    float:left;
  height: 100%;
  }


  #right
  {
    width:8px;
    width:30%;
    background-color:blue;
    float:right;
  height: 100%;
  }

  #left: first,
  #right: first,
  {
  content: "";
  height: 0;
  clear: both;
  display: block;
  }
  #content {
  height: 80%;
  }
  </style>
</head>
<body>
  <div id="wrapper">
      <div id="header">header</div>
      <div id="content">
       <div id="left"></div>
       content
       <div id="right"></div>
      </div>
      <div id="push"></div>
  </div>
  <div id="footer">footer</div>
</body>
</html>

我是这样的:

布局

希望这可以帮助!:)

于 2012-06-09T05:38:24.180 回答
0

<div id="footer">footer</div>

添加

<br style="clear:both;">
于 2012-06-09T05:27:25.243 回答