繁体   English   中英

在HTML页面顶部删除10px的空白

[英]Removing 10px of margin at top of HTML pages

我有一个非常简单的HTML页面,其中包含非常简单的样式表。 页面顶部的空白为10px ,不会消失。 这是我的布局和样式:

html, body {
    padding: 0;
    margin: 0;
    margin-top: -10px;
}

.main-container {
  with: 100%;
}

.left-column {
  width: 25%;
  float: left;
  background-color: lightblue;
  height: 500px;
  display: inline-block;
}

这是我的HTML

<!DOCTYPE html>
<html>
<head>
  <link href="styles.css" rel="stylesheet" type="text/css">
</head>
  <body>
    <main class="main-container">
      <aside class="left-column">

      </aside><!-- .left-column -->
      <section class="news-feed">
        <article class="story-item">
          <header class="story-title">
            <h1>This is the title of the post</h1>
          </header><!-- .story-title -->
          <p class="story-details">
            This is the body of the post
          </p>
        </article><!-- .story-item -->
      </section><!-- .news-feed -->
    </main><!-- .main-container -->
  </body>
</html>

H1标签的标准边距为10px,这会导致这种情况。 尝试重设:

*,html,body {
margin:0;
padding:0;
}

“ *”字符是全局选择器。

尝试这个,

body {    
    margin: 0 !important;
    padding: 0 !important;
}

使用reset或normalise.css

否则这通常会起作用。

body {
margin:0;
padding:0;
}

您的问题是h1标签使用的默认样式:

h1 {margin:0px;}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM