删除页眉和导航之间的间距

Removing the spacing between the Header and Nav

本文关键字:之间 导航 删除      更新时间:2023-09-26

我正试图为自己的网页设计公司构建我的网站。考虑到我在问一个基本问题,我这么做有点讽刺。另一方面,我只是建立基本的网站来获得经验。我的问题是,我试图消除标题和导航栏之间的间隙。我试图将它们都设置为固定位置,然后设置"顶部"值,但当浏览器窗口重新调整大小时,一切都不合适。它需要在移动和桌面设备上响应和查看。

<!DOCTYPE html>
<html>
    <head>
        <title>Picasso</title>
        <link rel="stylesheet" href="styling.css">
    </head>
    <body>
        <header>
            <img src="img/pwd_logo_05.png" alt="logo" id="logo">
            <h2>For Desktop &amp; Mobile </h2>
        </header>
        <nav>
            <ul>
                <li>Donate</li>
                <li>Request</li>
                <li>Contact</li>
                <li>Home</li>
            </ul>
        </nav>
    </body>
    <footer>
    </footer>
</html>

css

header {
    background-color: whitesmoke;
}
#logo {
    display: block;
    margin-left: auto;
    margin-right: auto;
    padding-top: 1.5em;
    width: 30%;
    height: 30%;
}
h2 {
    padding-bottom: 1em;
    text-align: center;
    font-family: sans-serif;
}
nav {
    width: 100%;
    background-color: black;
}
ul {
    list-style-type: none;
    overflow: hidden;
}
li {
    text-decoration: none;
    text-align: center;
    float: right;
    padding: .875em 1em;
    color: whitesmoke;
    font-family: sans-serif;
}
body {
    background-image:url(img/background.png);
}

这是因为为标题H2设置了边距。尝试将其"页边距底部"设置为0。

UL元件的"页边空白顶部"也是如此。

h2 css中删除padding-bottom: 1em;,从li css中删除padding: .875em 1em;

填充基本上将在元素周围保留空间,从而形成您现在看到的间隙。从css中删除填充将删除空间。

我的建议会回答你的问题,但可能不是最好的解决方案——你需要学习一些关于填充的知识,然后更改你的css,以便在正确的地方应用填充,避免在错误的地方使用填充。