我已经尝试了所提供解决方案的所有可能组合来消除该余量,例如:
body {
margin: 0 !important;
padding: 0 !important;
}
和
* {
margin: 0px;
padding: 0px;
}
和
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
但这没有帮助。事实上,我已经尝试了关于我的主题的前 5 个 stackoverflow 问题中几乎所有听起来合理的解决方案,但仍然没有结果。我的网页是:
body {
line-height: 1.6;
color: #3a3a3a;
font-family: "Arial", sans-serif;
}
a {
color: #fff;
text-decoration: none;
}
.main-header {
background: #3acec2;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Page Title</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header class="main-header">
<h1 class="name"><a href="#">Header text here</a></h1>
</header>
我使用的是 30.08 最新的标准化版本 7.0。
删除 h1
margin-top
和 body
标签的边距。
body {
line-height: 1.6;
color: #3a3a3a;
font-family: "Arial", sans-serif;
margin:0;
}
a {
color: #fff;
text-decoration: none;
}
.main-header {
background: #3acec2;
}
.main-header h1 {
margin-top: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Page Title</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header class="main-header">
<h1 class="name"><a href="#">Header text here</a></h1>
</header>
</body>
</html>
这里的
<h1>
边距实际上来自于normalize.css
本身:
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
当然,标签选择器比通用选择器更具体,这就是为什么使用
*
的解决方案不起作用。
实际的解决方案非常简单 -
style.css
:
h1 {
margin: 0;
}