html - body 不会拉伸(stretch)以适应它的内容

标签 html css

我搜索了很多解决方案来解决我的问题,但没有一个对我有用。 html 和正文不会拉伸(stretch)以适应其内容。 body 高度似乎是970px。我有这段代码:

HTML:

 <html>
 <head></head>
 <body onLoad='init()'>
     <div id='content'>
         <table class='pagecontent'>
             <tr><td id='content'>
                  some content
                 </td>
                  <td id='side'>
                  some other content
                 </td>
             </tr>
         </table>
     </div>    <div id='footer'>  
   <span class='copy'>&copy; 2014</span>    </div>  </body>  </html>

CSS:

 html, body {
     width:1000px;
 } 
 html {
     display: table;
     margin: auto; }

 body{
     display: table-cell; }
 #content{  
position:relative;  
top: 468px;     
height:auto;    
min-height: 200px;  
width:1000px;

 } table.pagecontent{
border-spacing: 0px;    
width:1000px;
height:1px;
padding-bottom: 60px;

td#side{
    width:300px;
        border: 1px solid black;
    border-left:20px solid black;
    margin-top: 0px;
    vertical-align: top;
    height:100%;


}
td#content{
    width:650px;
}
#footer{
    position:relative;
    bottom:0px;
    width:1000px;
    height:80px;
    background:url('../images/footer-back.png') no-repeat;
}

谢谢!

最佳答案

  1. 首先,永远不要多次使用同一个 ID。在您的代码中,“#content”被声明了两次。
  2. 不要设置 HTML 和 body 标签的宽度,最好在 body 内部使用一些带有类的 div 并设置其宽度。
  3. 如果规范没有要求,请勿使用表格进行页面布局。

您的代码的原始版本将类似于 example .

标记:

<div id="layout">
    <div class="pagecontent">
        <div id="content">some content</div>
        <div id="side">some other content</div>
    </div>
</div>
<div id="footer">  
    <span class="copy">&copy; 2014</span>
</div>

样式:

.pagecontent {
  margin-right: auto;
  margin-left: auto;
  width: 1000px;
}

#side {
  float: left;
  width: 350px;
}

#content {
  float: left;
  width: 650px;
}

#footer {
  margin-right: auto;
  margin-left: auto;
  width: 1000px;
  height: 80px;
  background: url('../images/footer-back.png') no-repeat;
}

希望对你有所帮助。

关于html - body 不会拉伸(stretch)以适应它的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25269567/

相关文章:

css - 如何在 bootstrap 4 container-fluid 中左对齐元素

jquery - x-editable 和 bootstrap datepicker css 冲突

javascript - 我如何强制将隐藏类(仅通过 JQuery 显示)加载到 mediaquery 上?

python - Django 静态文件 404(未找到)

html - 不带查询字符串链接到当前页面

javascript - Firefox 中输入 radio 中的 focus() 问题

jquery - 将外部事件拖放到 resourceWeek 时如何获取资源 ID?

html - 为什么 flex 元素不缩小过去的内容大小?

html - 文本对齐在 Safari 的 'select' 元素中不起作用

Javascript/jQuery 附加到 FormData() 返回 'undefined'