html - 导航栏下方的额外空间

标签 html css navigationbar

我目前正在尝试制作一个网站,并且设法创建了一个导航栏。但是,我的导航栏之间有一个奇怪的“额外”空间。一开始它工作正常,但在我引用了一个 JQuery 之后。但是,我怀疑 JQuery 是导致问题的原因,因为即使我将其删除,该网站看起来也一样。 Here's a screenshot of the problem. I'm trying to get rid of the circled part.

我的 HTML 代码:

        <div id="nav">                                                                  <!-- Navigation Bar -->
            <nav>                                                                   
                <ul>
                    <li><a class="selected" href="#">Home</a></li>
                    <li><a href="about.html">About Me</a></li>                          <!-- Link to about page -->
                    <li class="drop">
                        <a href="games.html" class="dropbtn">Games</a>
                        <div class="drop-content">
                            <a href="rfg.html">Red Faction: Guerrilla</a>       <!-- Contains links to the respective pages -->
                            <a href="wots3.html">Way of the Samurai 3</a>
                            <a href="singularity.html">Singularity</a>
                        </div>
                    </li>
                    <li><a href="reviews.html">Reviews</a></li>
                    <li><a href="external.html">External Store</a></li>                 <!-- Link to external site -->
                    <li><a href="video.html">Videos</a></li>                            <!-- Contains links to Youtube -->
                    <li><a href="feedback.html">Feedback</a></li>                       <!--Feedback form-->

这是样式表:

#nav nav{                                   /* Navigation bar*/
padding-top: 5%;
margin-bottom: 5% }

#nav ul {
list-style-type: none;
margin: 0;
background-color: #1C86EE;
padding: 0;
position: relative;
width: 100%;
bottom: 0;
display: inline-block }

#nav li {
float: left;
width: 14% }

li a, .dropbtn {
display: inline-block;
color: #FFFFFF;
text-align: center;
padding-left: 15%;
padding-right: 15%;
text-decoration: none }

.selected {
background-color: #6CCC0A;
padding-right: 25% }

li a:hover, .drop:hover .dropbtn {
background-color: #BFA810 }

a {
padding-top: 1em;
padding-bottom: 1em }

li.drop {
display: inline-block }

.drop-content {
display: none;
position: absolute;
background-color: #970707;
min-width: 14%;
box-shadow: 0px 8px 16px 0px #000000;
z-index: 100 }

.drop-content a {
color: #FFFFFF;
padding: 15px 20px;
display: block;
text-align: left }

.drop-content a:hover {
background-color: #02BBC4 }

.drop:hover .drop-content {
display: block;
border: 1px solid black;
position: absolute }                                /*End of navigation*/

* {                                     /* index style */
box-sizing:border-box
}
body {
font-family: Verdana,sans-serif;
margin:0
}
.slideshow-fade {
display:none
}

/* Slideshow container */
.slideshow {
 max-width: 100%;
 position: relative;
 margin: auto;
}
.slideshow img {
opacity: 0.7
}

/* Next & previous buttons */
.prev, .next {
 cursor: pointer;
 position: absolute;
 top: 50%;
 width: auto;
 padding: 1em;
 margin-top: -1em;
 color: #FFFFFF;
 font-weight: bold;
 font-size: 1.5em;
 transition: 0.6s ease;
 border-radius: 0 3px 3px 0;
}

/* Position the "next button" to the right */
.next {
 right: 0;
 border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
 background-color: rgba(0,0,0,0.8);
}

/* Caption text */
.text {
 color: #000000;
 font-size: 1.3em;
 padding: 1% 2%;
 position: absolute;
 bottom: 2%;
 width: 100%;
 text-align: center;
}

/* Number text (1/3 etc) */
.number {
 color: #000000;
 font-size: 1em;
 padding: 8px 12px;
 position: absolute;
 top: 0;
}

/* The dots/bullets/indicators */
.dot {
 cursor: pointer;
 height: 1em;
 width: 4%;
 margin: 0 2px;
 background-color: #bbbbbb;
 border-radius: 50%;
 display: inline-block;
 transition: background-color 0.6s ease;
}

.active, .dot:hover {
 background-color: #717171;
 }

/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
 animation-name: fade;
 animation-duration: 1.5s;
}

@-webkit-keyframes fade {
from {opacity: .4} 
to {opacity: 1}
}

@keyframes fade {
from {opacity: .4} 
to {opacity: 1}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width : 720px ){
.prev, .next,.text {font-size: 11px}
}
.slideshow-fade a {
color: #FFFFFF
}
.slideshow-fade a:visited {
color: #5115D0
}                                               /*End of style for index*/
footer {                                    /*Footer*/
background: #000000;
width: 100%;
height: 5%;
position: relative;
bottom: 0;
left: 0;
padding-top: 2%;
overflow: hidden;
}
footer p {
font-family: arial, calibri, sans-serif;
color: #FFFFFF;
text-align: center;
padding-bottom: 2%;
}                               /*End of footer*/

任何帮助将不胜感激。谢谢。

这里放上jsfiddle文件,方便大家看问题。 https://jsfiddle.net/8xutoea5/

编辑:添加了更多 CSS 代码。 编辑:我解决了这个问题。感谢大家花时间解决这个问题。

最佳答案

这似乎是您 CSS 中其他地方的边距,此处未提供,这是导致问题的原因。您可以尝试在几个地方设置 margin-bottom:0; 看看是否可以解决问题。

#nav nav ul li {                                 
    margin-bottom: 0;
    padding-bottom: 0;
}


#nav nav ul li a {                                 
    margin-bottom: 0; 
}

或者提供样式表的其余部分。

关于html - 导航栏下方的额外空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42140350/

相关文章:

html - 如何使用 ul > li > div 显示表格单元格自动宽度 100%

javascript - 动画的心图标

java - JavaFX CSS 中的 StyleableProperty

html - 如何将导航栏移动到其他位置?

html - 顶部和子导航之间的空间

javascript - 使用 JavaScript 更改链接单击时的当前列表元素

html - IE 7 中的背景图像问题

javascript - EPUB 分数捕捉

html - 顶部边距在两个 Div 上都没有移动

ios - 按下后退按钮时,上一个屏幕上的导航标题消失