CSS渲染不是应该的

时间:2013-07-24 11:29:16

标签: html css

这就是我的页面外观,任何人都可以注意到它没有正确呈现: enter image description here

我将在我的问题中发布HTML和部分CSS。

<body>
<img id="logo" src="res/img/logo.png" />
<div id="content">
    <div id="main-panel">
      <div class="headline">People in the database</div>
      <table width="100%" border="0" id="people">
          <tr class="table-headline">
            <td width="3%">#</td>
            <td width="90%">Name</td>
            <td width="7%">&nbsp;</td>
           </tr>
      </table>
    </div>

    <div id="right-panel">
        <div class="headline">Here is where the tools will be posted</div>
        This is the tools panel.
    </div>
</div>
</body>
</html>

和CS ......

html {
    text-align: center;
    background-color: #eeeeee;
    -webkit-box-shadow: 10px 20px 20px #666;
    box-shadow: 10px 20px 20px #666;
}
body {
    margin-left: auto;
    margin-right: auto;
    background-color: #ffffff;
    width: 960px;
    text-align: left;
    border-radius: 4px;
    border: 1px solid #666;
    padding-top: 10px;
    -webkit-box-shadow: 0px 6px 15px 0px #aaa;
    box-shadow: 0px 6px 15px 0px #aaa;
    -moz-box-shadow: 0px 6px 15px 0px #aaa;
    padding-right: 10px;
    padding-bottom: 10px;
    padding-left: 10px;
}

#logo {
    width: 150px;
    height: auto;
    margin-bottom: 10px;
}

#content {
    position: relative;
    min-height: 400px;
    font-size: 14px;
}
#content .headline  {
    height: 24px;
    padding-left: 5px;
    padding-right: 5px;
    font-family: "Segoe UI";
    font-size: 12px;
    line-height: 24px;
    background-image: url(img/headlineBackground.png);
    clear: right;
    float: none;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border-bottom-color: #666666;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    -moz-border-radius-topleft: 5px;
    -moz-border-radius-topright: 5px;
    -webkit-border-top-left-radius: 5px;
    -webkit-border-top-right-radius: 5px;
}

#content #main-panel {
    width: 740px;
    margin-right: 10px;
    float: left;
    position: relative;
}
#content #right-panel {
    float: right;
    position: relative;

}

我会搜索谷歌,但我真的不知道该找什么...请告诉我哪里出错了,也许还有办法改善我的CSS ...当然告诉我你是否需要更多帮助我!

2 个答案:

答案 0 :(得分:2)

您正在浮动容器元素内的元素,只需在父div关闭之前添加此行以清除浮动

<div style="clear: both;"></div>
<!-- Don't use inline styles, I've used it only for a demo 
     purpose here, consider using a self clearing class or a 
     class with a property clear: both; -->

Demo

有关clear: both;

的更多信息

还有其他各种方法来清除浮动,例如在容器元素上使用overflow: hidden;,我不建议使用它,或者使用像这样的自清除类

.clear:after {
   clear: both;
   display: table;
   content: ' ';
}
  

注意::after在IE8中不起作用,你可以使用CSS3 pie作为polyfill来使CSS3伪选择器工作。

答案 1 :(得分:0)

清除浮动div下方的行,如下所示:

<body>
<img id="logo" src="res/img/logo.png" />
<div id="content">
    <div id="main-panel">
      <div class="headline">People in the database</div>
      <table width="100%" border="0" id="people">
          <tr class="table-headline">
            <td width="3%">#</td>
            <td width="90%">Name</td>
            <td width="7%">&nbsp;</td>
           </tr>
      </table>
    </div>

    <div id="right-panel">
        <div class="headline">Here is where the tools will be posted</div>
        This is the tools panel.
    </div>
    <br style="clear: both;" />
</div>
</body>
</html>

或者,您可以使用display: inline-block将两者设置为相邻。