【问题标题】:CSS - A white gap between my HTML and BODYCSS - 我的 HTML 和 BODY 之间的空白
【发布时间】:2013-04-12 15:18:51
【问题描述】:

我正在尝试将 HTML5 Boilerplate + Normalize.css 用于我当前的项目,但遇到了以下问题。

我的 HTML 标签和我的 BODY 标签之间似乎有一个间隙。 我试图弄清楚这是什么原因,但经过多次尝试都失败了。

我一定在这里或那里错过了什么。

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>Ridanis | Web Design &amp; Web Development</title>

<meta name="description" content="">
<meta name="viewport" content="width=device-width">

<link rel="stylesheet" href="css/normalize.min.css">
<link rel="stylesheet" href="css/main.css">

<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->

<!-- Wrapper / Start -->
<div class="wrapper">
<h1>Hello World!</h1>
</div>
<!-- Wrapper / End -->

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>

<script src="js/main.js"></script>
</body>
</html>

这是一个小提琴:http://jsfiddle.net/C7gbC/

提前致谢。

【问题讨论】:

  • 您应该知道,如果有人使用浏览器(不是 Internet Explorer),则该浏览器很可能没有 HTML 语句。该页面应该可以正常工作,但不再是有效的 HTML。
  • 技术背景:这称为“相邻边距”,见w3.org/TR/CSS21/box.html#collapsing-margins
  • @CBroe:准确地说,这种现象被称为折叠边距。在某些情况下,相邻边距不能折叠。
  • 不,这是相邻的边距——“盒子的上边距和它的第一个流入孩子的上边距”

标签: css html boilerplate normalize


【解决方案1】:

发现这是我的页眉中“h2”的问题。 iE8 和 Crome 中的“p”标签相同。只需设置边距:0;对于我在 main.css 页面开头设置的一些结构样式的“h1”和“p”标签。解决方案似乎有效

【讨论】:

    【解决方案2】:

    normalize.css 根据浏览器默认值在h1 元素上插入默认边距声明以保持一致性:

    h1 {
        font-size: 2em;
        margin: 0.67em 0;
    }
    

    如果您手动将其归零(在主样式表中或直接修改 normalize.css),差距将消失:

    h1 {
        margin: 0;
    }
    

    【讨论】:

    • 我把H1改成了P标签,问题依旧。
    • @Khaled:这就是我说手动删除边距的原因。我没说要把h1改成p
    • 还是一样,没有任何改变。
    • 嗯,这似乎对 Fiddle 有效,但由于某种原因不在我的主脚本中。会不会是 Modernizer.js 或 Respond.js 造成的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多