我的内容周围有未知的白色边框

3 html css margin

我创建了一个非常简单的页面,只有几个元素。我的“内容 div”周围有白色边框,无法弄清楚是什么原因造成的。它仅出现在我的内容的顶部和左侧。我尝试用 .body { border: 0; 删除它 },但这没有帮助。还有一些与我的 CSS 有关的其他问题,但已解决。

这是我的 HTML 代码:

<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8' />
    <title>Olivera Miletic graphic desig</title>
    <link rel='stylesheet' href='style.css' />
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
</head>

<body>
    <div class="container">
        <div class="mainText">
            <p> OLI<span class="secondColor">APPARENTLY </p>
             <p class="stayTuned"> SOON. STAY TUNED. </p>
          </div>
                  <div>
                      <p class="meanWhile"> meanwhile <a href="http://www.oliveramiletic.com" target="_blank"> WORK </a> / <a href="https://www.behance.net/olivera_m" target="_blank"> BE </a> / <a href="https://twitter.com/oliapparently" target="_blank"> TW </a> / <a href="mailto:miletic.olivera@gmail.com" > MAIL </a>
                      </p>
                 </div>
          </div>
      </body>
    </html>
Run Code Online (Sandbox Code Playgroud)

这是我的CSS:

.container {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow:hidden;
    background-color: #6600cc;
    padding: 20px 0px 0px 50px;
    display: box;
}

.body {
    margin: 0;
}

.mainText {
    font-family: 'Open Sans', sans-serif;
    font-size: 64px;
    color: #FF0066;
    font-weight: bolder;
    line-height: 0%;
    margin-bottom: 70px;

}

.secondColor {
    color: #00ccff;
}

.stayTuned {
    font-family: 'Open Sans', sans-serif;
    font-size: 25px;
    color: #ffffff;
    font-weight: bolder;
}

.meanWhile {
    font-family: 'Open Sans', sans-serif;
    color: #ffffff;
    font-weight: lighter;
}

a {
  color: #ffffff;
  text-decoration: none; 
}
Run Code Online (Sandbox Code Playgroud)

这是 JSFiddle https://jsfiddle.net/1yL1ta5x/和代码:

另外,希望获得有关如何优化它的建议,至少是网页的移动和桌面视图和/或对我的代码的任何其他优化。我是一个绝对的初学者,所以请耐心等待。谢谢。

问候,

nas*_*eez 9

某些浏览器/框架/环境将 default margin,padding值添加到bodyhtml.

您必须将margins/覆盖paddinghtmlorbody才能使空白消失。

只需添加以下内容:

html, body {
  margin: 0;
  padding: 0;
}  
Run Code Online (Sandbox Code Playgroud)

编辑

要回答你的第二个问题,为什么你的 div 上有滚动,发生这种情况是因为containerdiv 占据了其父级的 100% ,并且还占据了20px50px。 因此widthheight padding-top padding-left
containerdiv 溢出了它的父级从而产生了滚动。

一般修复方法是应用box-sizing: border-boxcontainer,以便将padding包含在width和中height

.container {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #6600cc;
    padding: 20px 0px 0px 50px;
    box-sizing: border-box;
}
Run Code Online (Sandbox Code Playgroud)

检查更新的小提琴:https://jsfiddle.net/1yL1ta5x/1/

我建议您阅读有关box-sizing和整个css 盒子模型的更多信息。