html - 悬停时导航列表项占用过多空间

标签 html css

当我悬停在“Newsletter”上时它占用了很大的空间,我尝试调整边距但没有任何反应,我也尝试了 margin-leftmargin-right 但问题是一样的。下面是代码:

hr {
  margin: 0px;
}
body {
  background: url(../images/bg.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  word-wrap: break-word;
}
h1 {
  font-family: "Sacramento";
  color: #F0FFF0;
}
.title >h1 {
  color: #222;
  transition: color 2s;
}
.title:hover >h1 {
  color: #6565f0;
}
.title {
  line-height: 40px;
  margin-top: 0px;
  margin-bottom: -22px;
  font-size: 19px;
  transition: font-size 0.4s;
}
.title:hover {
  font-size: 22px;
}
.nav ul {
  background-color: transperent;
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: center;
}
.nav li {
  font-family: 'Oswald', sans-serif;
  font-size: 1.2em;
  line-height: 40px;
  margin-top: 10px;
  height: 40px;
  border-bottom: 1px solid #888;
  transition: font-size 0.4s;
}
.nav li:hover {
  font-size: 1.6em;
}
.nav a {
  text-decoration: none;
  color: #222;
  display: block;
  transition: .3s background-color;
}
.nav a:hover {
  background-color: #005f5f;
}
.nav a.active {
  background-color: #fff;
  color: #444;
  cursor: default;
}
@media screen and (min-width: 600px) {
  .nav li {
    width: 120px;
    border-bottom: none;
    height: 50px;
    line-height: 50px;
    font-size: 1.4em;
  }
  /* Option 1 - Display Inline*/
  .nav li {
    display: inline-block;
    margin-right: 10px;
    margin-left: 10px;
  }
}
<font align=center>
  <div class="title">
    <h1>Welcome</h1>
  </div>
</font>
<hr />
<div class="nav">
  <ul>
    <li class="home"><a href="#">Home</a>
    </li>
    <li class="tutorials"><a href="#">Tutorials</a>
    </li>
    <li class="about"><a href="#">About</a>
    </li>
    <li class="news"><a href="fb.com" target=_blank>Newsletter</a>
    </li>
    <li class="contact"><a href="#">Contact</a>
    </li>
  </ul>
</div>
<hr style="margin-top:5px;" />

最佳答案

更新li的宽度为width:130px;

.nav li {
   width:130px;
}

关于html - 悬停时导航列表项占用过多空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32961598/

相关文章:

html - 特异性选择 li with css in mega drop down

javascript - FlotJS 工具提示扰乱了响应能力?

html - 如何解决 CSS page-break-inside : avoid; failing to avoid break?

html - CSS3PIE 不适用于边界半径

Jquery,计算字段总和(动态)

javascript - 如何使用 AngularJS 将一个人从 DropDownList (ddl 位于表 1 )移动到另一个表(表 2)?

html - CSS 下拉问题

html - CSS - 跨浏览器导航 Div 大小

javascript - 我的 href 链接按钮无法联机使用

javascript - 在不离开页面的情况下更改按钮的颜色