html - 单击时导航中的元素会稍微分开

标签 html css nav

我有一个包含 4 个元素的导航元素。 当我单击任何元素时,我注意到这些元素稍微分开,并且 div 展开。

<div id="siteNavigation" class="navDiv">
  <nav>
    <ul>
      <li><span><a href="index.html" class="selected">Home</a></span></li>
      <li><a href="resources\waiting_room.jpg">Meet Me</a></li>
      <li><a href="resources\waiting_room.jpg">About</a></li>
      <li><a href="resources\waiting_room.jpg">Contact</a></li>
    </ul>
  </nav>
</div>


.navDiv {
  display: inline;
  width: auto;
  float: right;
  border: solid;
}

nav ul {
  clear: both;
  list-style-position: inside;
  clear: left;
  list-style: none;
  margin-left: 0;
  width: auto;
  padding-top: 32px;
  text-align: center;
  white-space: nowrap;
}

nav ul li {
  display: inline-block;
  white-space: nowrap;
  padding-left: 8px;
  border: none;
}

nav ul li a {
  color: #000000;
  /* #E3CF9C */
  font-size: 1em;
  font-weight: bold;
  text-decoration: none;
  letter-spacing: 0.05em;
  padding: 10px 3.125% 26px 3.125%;
  text-transform: uppercase;
  border: none;
}

nav ul li a:hover {
  color: #BF0000;
}

nav ul li a.selected {
  color: #BF0000;
}

nav ul li a.selected:hover {
  color: #E3CF9C;
}

JSFiddle 示例:https://jsfiddle.net/rfhasw48/1/

我需要更改什么才能使导航保持恒定大小?

最佳答案

只需从 nav ul li a 中删除填充。

更新的 CSS:

    .navDiv {
  display: inline;
  width: auto;
  float: right;
  border: solid;
}

nav ul {
  clear: both;
  list-style-position: inside;
  clear: left;
  list-style: none;
  margin-left: 0;
  width: auto;
  padding-top: 32px;
  text-align: center;
  white-space: nowrap;
}

nav ul li {
  display: inline-block;
  white-space: nowrap;
  padding-left: 8px;
  border: none;
}

nav ul li a {
  color: #000000;
  /* #E3CF9C */
  font-size: 1em;
  font-weight: bold;
  text-decoration: none;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: none;
}

nav ul li a:hover {
  color: #BF0000;
}

nav ul li a.selected {
  color: #BF0000;
}

nav ul li a.selected:hover {
  color: #E3CF9C;
}

关于html - 单击时导航中的元素会稍微分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46413152/

相关文章:

html - 文本输入上可见溢出,这可能吗?

javascript - OnMouseScroll 自增一个变量 JS

css - HTML 表格卡住分栏布局

javascript - 如何删除光滑轮播中的背景?

javascript - 用于保存下拉值的 session 存储

html - 带导轨的 Bootstrap : Align a dropup with other element in a footer

twitter-bootstrap - 导航栏中文本上方/上方/上方居中的图标? ( Bootstrap 3)

html - 简单的导航栏滚动间隙

html - 在CSS中居中div但远离左侧导航

jquery - 滚动表格中的弹出显示