第一个元素和页面顶部之间的间隙

xma*_*fly 1 html css

我有以下代码:

    body {
        height: 100vh;
        margin: 0px;
        margin-top: 0px;
        flex-direction: column;
        background-color: rgb(41, 11, 22);
    }
    
    nav {
        color: white;
        background-color: rgb(214, 50, 50);
        height: 10vh;
    }
Run Code Online (Sandbox Code Playgroud)
 <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="index.css">
        <title>Navbar Animations</title>
    </head>
    <body>
        <nav>
            <p>This is a test</p>
        </nav>
    </body>
    </html>
Run Code Online (Sandbox Code Playgroud)

但最终的结果是这样的:

网站

问题是:我如何消除顶部的差距?

lik*_*kle 5

这是因为 p 的边距,您可以将其删除:

p {
  margin: 0;
}
Run Code Online (Sandbox Code Playgroud)