html - 导航栏和 "Jumbotron"之间的空白

标签 html css web

我没有使用 bootstrap,但是我想在我的 Nav 正下方添加一个类似 div 的“Jumbotron”。

但是,我的导航栏和 div 之间有一个小的空白区域,我不知道它从哪里获得边距。

我用过 chrome 元素检查器,它们之间没有可识别的边距。

我已将正文标签设置为 0 边距和 0 填充,我尝试将各种元素和标签调整为 0,唯一有效的是 *,但我希望尽可能避免使用星号。

    <!DOCTYPE html>
    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="Display01.css">
            <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
            <title>Display 01</title>
        </head>
        <body>
        <!-- Ignore the nav - It is used to modeling purposes-->
        <!-- Jump to line 27 -->
        <nav>
            <div class="toggle">
                <h3>Logo</h3>
                <i id="menu" class="fas fa-bars"></i>
            </div>
            <ul>
                <li><a href="#"></a>Home</li>
                <li><a href="#"></a>About</li>
                <li><a href="#"></a>Services</li>
                <li><a href="#"></a>Portfolio</li>
                <li><a href="#"></a>Contact</li>
            </ul>
        </nav>
<!-- Begin Main Content -->
        <div class="display"><p>Test</p></div>
        <script type="text/javascript" src="Display01.js"></script>
        </body>
    </html>

.display {
    margin-bottom: 2rem;
    margin-top: 0;
    background-color: #e9ecef;
    padding-right: 0;
    padding-left: 0;
    border-radius: 0;
    width: 100vw;
    height: 50vh;
}



/*CSS Used for Navbar for Modeling Purposes*/
body {
    margin: 0;
    padding: 0;
    font-family: sans-serif;
}
nav {
    width: 100%;
    background-color: #00316b;
    color: #fff;
    text-decoration: none;
    overflow: auto;
}
ul {
    width: 80%;
    margin: 0 auto;
    padding: 0;
}
ul li {
    list-style: none;
    display: inline-block;
    padding: 20px;
    font-weight: bold;
    transition: 0.5s;
}
ul li:hover {
    /*background-color: #e91e63;*/
    background-color: white;
    color: #000;
    border-radius: 15px;
}
h3 {
    float: left;
    position:relative;
    margin: 0 0 20px 10px;
}
.menu {
    float: right;
}
.toggle {
    width: 100%;
    padding: 10px;
    background-color: #00316b;
    text-align: right;
    box-sizing: border-box;
    font-size: 30px;
    display: none;
}
@media (max-width:768px){
    .toggle {
        display: block;
    }
    ul {
        width: 100%;
        display: none;
        transition: 1.0s;
    }
    ul li {
        display: block;
        text-align: center;
    }
    .active {
        display: block;
    }
}

我希望 Display Div 与导航栏齐平,没有空白。

一段时间以来,我一直在努力解决这个问题,非常感谢您提供的帮助。

最佳答案

边距来自显示 div 内的段落元素。您可以删除该边距。

您还可以为显示 div 设置负边距。

当您使用开发者工具最左上角的按钮,然后将鼠标悬停在不同的元素上时,您可以看到边距的来源。

关于html - 导航栏和 "Jumbotron"之间的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56008557/

相关文章:

javascript - JavaScript 函数声明是否返回对函数的引用?

html - 为什么我的 Logo 和导航栏之间存在巨大的可点击间隙以及如何消除它?

html - Rails - 电子邮件字符串拒绝在表格内自动换行

javascript - 给定一个 html 字符串,在 javascript 中仅删除 anchor HTML 标签的最佳方法是什么?

css - 如何将 "hover"和 "visited"样式应用于 asp.net 外部 css 页面中现有样式中的超链接

html - 在图像之间放置详细列表。(CSS/Html)

javascript - 在样式为 ="pointer-events: none; cursor: default;"的 iframe 中使元素可点击

php - 在 html 标签中的鼠标悬停中的 setTimeOut 函数中使用 php 变量

html - css 边距未响应

asp.net - 构建一个新的 ASP.NET 应用程序 - 寻找一个好的框架