当我清除时,为什么我会得到一条白线?

时间:2011-02-16 06:43:13

标签: css html

我正试图让h1出现在左边,而h2出现在右边,这是我设法做的,这要归功于之前关于stackoverflow的帖子。但是现在有一条白线出现在文字下面,严重搞乱了我的设计。有什么想法吗?

<div id="container">
  <div id="header">
    <h1 style="text-align:left;float:left;">Ken DeRosier</h1>
    <h2 style="text-align:right;float:right;">Master Sculptor</h2> 
    <hr style="clear:both;">
    <!-- end #header -->
  </div>
  ...
</div>

这是我能想到的可能影响上述代码的所有CSS。

body  {
    margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
    padding: 0;
    text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    color: #FFFFbb;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 100%;
    background-color: #000000;
    background-repeat: no-repeat;
    background-position: center top;
    background-image: url(../images/sunriseHeader.jpg);
}
.thrColLiqHdr #container { 
    width: 80%;  /* this will create a container 80% of the browser width */
    margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
    border: 0px solid #000000;
    text-align: left; /* this overrides the text-align: center on the body element. */
} 
.thrColLiqHdr #header {
    padding: 0 10px;
    padding-top: 170px;
    padding-right: 20px;
} 
.thrColLiqHdr #header h1 {
    margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
    padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */

2 个答案:

答案 0 :(得分:2)

我认为这是因为您使用了<hr>又名“横向规则”。为什么不尝试使用spandiv或其他内容来清除哪些内容并非用于显示某些内容?

答案 1 :(得分:2)

尝试替换此行

<hr style="clear:both;">

用这个

<div style="clear:both;"></div>