【问题标题】:Another space between divs issue, other answers not workingdivs问题之间的另一个空间,其他答案不起作用
【发布时间】:2013-03-09 16:50:17
【问题描述】:

网页中只有一个 div 之间有一个空格。将其重新创建为 jsfiddle http://jsfiddle.net/durN4/

问题在于“Switzerland Inn on the Blue Ridge Parkway”横幅与其下方的正文之间。 div 标签的顶部和底部都有一个空格。这是在 jsfiddle 页面上找到的 css 代码...

#main_holder {
width: 75%;
min-width: 750px;
margin-right: auto;
margin-left: auto;
border: 5px solid #E2BE6A;
position: relative;
-moz-box-shadow: 0px 0px 21px 5px rgba(2, 1, 14, 0.6);
-webkit-box-shadow: 0px 0px 21px 5px rgba(2, 1, 14, 0.6);
box-shadow: 0px 0px 21px 5px rgba(2, 1, 14, 0.6);
height: auto;
}
#headline {
height: 155px;
border-bottom: 5px solid #E2BE6A;
width: 100%;
background: -ms-linear-gradient(top left, #FFFFFF 0%, #327EEF 100%);
background: -moz-linear-gradient(top left, #FFFFFF 0%, #327EEF 100%);
background: -o-linear-gradient(top left, #FFFFFF 0%, #327EEF 100%);
background: -webkit-gradient(linear, left top, right bottom, color-stop(0, #FFFFFF), color-stop(1, #327EEF));
background: -webkit-linear-gradient(top left, #FFFFFF 0%, #327EEF 100%);
background-image: linear-gradient(to bottom right, #FFFFFF 0%, #327EEF 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#FFFFFF",endColorstr="#327EEF",GradientType=1);
}
#rotator_holder {
height: 321px;
width: 100%;
border-bottom-width: 5px;
border-bottom-style: solid;
border-bottom-color: #E2BE6A;
position: relative;
}
#navbar {
height:35px;
width: 100%;
border-bottom-width: 5px;
border-bottom-style: solid;
border-bottom-color: #E2BE6A;
position: relative;
background-color: #FFF1CE;

}
#titlebar {
font-family: 'Habibi', serif;
font-size: 24px;
height: 30px;
width: 100%;
background: -ms-linear-gradient(top left, #327EEF 0%, #FFFFFF 100%);
background: -moz-linear-gradient(top left, #327EEF 0%, #FFFFFF 100%);
background: -o-linear-gradient(top left, #327EEF 0%, #FFFFFF 100%);
background: -webkit-gradient(linear, left top, right bottom, color-stop(0, #327EEF), color-stop(1, #FFFFFF));
background: -webkit-linear-gradient(top left, #327EEF 0%, #FFFFFF 100%);
background-image: linear-gradient(to bottom right, #327EEF 0%, #FFFFFF 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#327EEF",endColorstr="#FFFFFF",GradientType=0);
color: #000;
padding-top: 10px;
padding-bottom: 10px;
}
#main_content {
font-size: 18px;
background-color: #FFF1CE;
width: 100%;
-moz-box-shadow: inset 0px 0px 13px 6px #c4c6cf;
-webkit-box-shadow: inset 0px 0px 13px 6px #c4c6cf;
box-shadow: inset 0px 0px 13px 6px #c4c6cf;
}
#padding {
width: 94%;
margin-right: auto;
margin-left: auto;
font-family: "Open Sans", sans-serif;
}

【问题讨论】:

  • 我建议使用padding-left 而不是  来缩进文本。

标签: html spaces


【解决方案1】:

您看到的内容称为collapsing margins。正文中 h1 元素的边距将其容器向下推。

当一个元素没有内边距或边框,而子元素有边距时,该边距不适用于子元素和父边界之间,而是在父元素之外。

因此,有几种方法可以修复它,具体取决于您想要的结果:

  • 删除h1元素的上边距
  • 在容器顶部添加填充
  • 在容器顶部添加边框

【讨论】:

    【解决方案2】:

    您的问题是由h1main_content 中的最后一个p 的边距引起的。

    jsFiddle

    #main_content p:last-child {
        margin-bottom: 0;
    }
    
    #main_content h1 {
        margin-top: 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-23
      • 2021-10-18
      • 2017-06-07
      • 2010-11-16
      • 1970-01-01
      • 2017-09-21
      相关资源
      最近更新 更多