导航栏中按钮下的不需要的间距

时间:2017-11-18 07:36:59

标签: html css

我是网站编码的新手,目前正在做作业。

我的问题是当鼠标悬停在我的导航栏上时,悬停颜色并不能完全覆盖整个项目。我该如何解决这个问题?它是否因我的徽标而发生?

Like so...

我的HTML代码:

.navigation {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: rgb(134, 35, 35);
  font-family: Megrim, cursive;
  font-weight: bold;
}


/* floats navigation buttons to the right */

.naviright {
  float: right;
}


/*makes elements start from the left*/

.navigation li {
  float: left;
}

.navigation li a {
  display: block;
  color: white;
  text-align: center;
  padding: 12px 16px;
  text-decoration: none;
}


/* Change the link color to #111 (black) on hover */

.navigation li a:hover:not(.active) {
  background-color: #111;
}

.navigation li a:hover:active {
  background-color: #4CAF50;
}


/*TopNav End*/


/*logo*/

#logo {
  width: 40px;
  height: 40px;
  overflow: hidden;
  padding-left: 20px;
  padding-bottom: 5px;
  padding-top: 2px;
}

#logoname {
  color: rgb(255, 255, 255);
  font-size: 20px;
}
<nav>
  <ul class="navigation">
    <li id="logo"><img src="images\logo.svg"></li>
    <li id="logoname"><a>Stationery Haven</a></li>
    <div class="naviright">
      <li><a href="index3.html">Home</a></li>
      <li><a href="#">Categories</a></li>
      <li><a href="#">Feedback</a></li>
      <li><a href="#">Contact Us</a></li>
    </div>`enter code here`
  </ul>
</nav>

3 个答案:

答案 0 :(得分:0)

将行高添加到li a

.navigation li a {
  display: block;
  color: white;
  text-align: center;
  padding: 12px 16px;
  text-decoration: none;
  line-height:22px;
} 

.navigation {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: rgb(134, 35, 35);
  font-family: Megrim, cursive;
  font-weight: bold;
}


/* floats navigation buttons to the right */

.naviright {
  float: right;
}


/*makes elements start from the left*/

.navigation li {
  float: left;
}

.navigation li a {
  display: block;
  color: white;
  text-align: center;
  padding: 12px 16px;
  text-decoration: none;
  line-height:22px;
}


/* Change the link color to #111 (black) on hover */

.navigation li a:hover:not(.active) {
  background-color: #111;
}

.navigation li a:hover:active {
  background-color: #4CAF50;
}


/*TopNav End*/


/*logo*/

#logo {
  width: 40px;
  height: 40px;
  overflow: hidden;
  padding-left: 20px;
  padding-bottom: 5px;
  padding-top: 2px;
}

#logoname {
  color: rgb(255, 255, 255);
  font-size: 20px;
}
<nav>
  <ul class="navigation">
    <li id="logo"><img src="images\logo.svg"></li>
    <li id="logoname"><a>Stationery Haven</a></li>
    <div class="naviright">
      <li><a href="index3.html">Home</a></li>
      <li><a href="#">Categories</a></li>
      <li><a href="#">Feedback</a></li>
      <li><a href="#">Contact Us</a></li>
    </div>`enter code here`
  </ul>
</nav>

答案 1 :(得分:0)

好的,我查看过您的代码我认为如果您添加或更改以下css代码,那么它将适用于您:

#logo {
 width: 40px;
 height: 40px;
 overflow: hidden;
 padding-left: 20px;
 padding-bottom: 4px; // Changed here 5px to 4px
 padding-top: 2px;
}

.navigation li a {
  display: block;
  color: white;
  text-align: center;
  padding: 12px 16px;
  line-height: 22px; // Logo test font-size: 20px; so this line need to be added
  text-decoration: none;
}

答案 2 :(得分:0)

1)你可以通过增加

的大小来解决这个问题

.naviright li a {font-size: 20px;}

2)或者您可以将行高设为 -

.navigation li a {line-height: 22px;}

以下是我尝试Fiddle

的基于flex的解决方案