导航栏在悬停上的差距

时间:2017-07-11 11:22:52

标签: android html css cordova

enter image description here

我正在使用cordova android应用程序,我试图制作导航栏,我已经创建了它,但它有一个空白。我不知道这个差距来自哪里,我想消除这个差距。

这是我的HTML:

<nav class="fixed-nav">
        <ul>
            <li><a href="#"><img src="image/cofee.png" height="30" class="menu-icon"/>Cofee</a></li>
            <li><a href="#"><img src="image/koki.png" height="30" class="menu-icon"/>Restaurant</a></li>
            <li><a href="#"><img src="image/beer.png" height="30" class="menu-icon"/>Drinks & Nightlife</a></li>
        </ul>
    </nav>

这是我的CSS:

.fixed-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #ddd;
    white-space: nowrap;
    height: 50px;
    box-sizing: border-box;
    padding: 10px;
    box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16), 0px 3px 6px rgba(0, 0, 0, 0.23);
}

.fixed-nav ul,
.fixed-nav li {
    display: inline;
}

.fixed-nav a {
    text-decoration: none;
    text-transform: uppercase;
    padding: 17px 10px;
    color: #333;
    font-family: arial;
}

.fixed-nav a:hover {
    background-color: #000;
    color: #eee;
}

.fixed-nav ul {
    padding: 0;
}

.fixed-nav img {
    vertical-align: middle;
}

.menu-icon{
    margin-right: 5px;
}

main {
    margin-top: 55px;
}

2 个答案:

答案 0 :(得分:1)

.fixed-nav 中更改 填充

padding: 10px;

padding: 10px 0px;

尝试以下代码,

.fixed-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #ddd;
    white-space: nowrap;
    height: 50px;
    box-sizing: border-box;
    padding: 10px 0px;
    box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16), 0px 3px 6px rgba(0, 0, 0, 0.23);
}

.fixed-nav ul,
.fixed-nav li {
    display: inline;
}

.fixed-nav a {
    text-decoration: none;
    text-transform: uppercase;
    padding: 17px 10px;
    color: #333;
    font-family: arial;
}

.fixed-nav a:hover {
    background-color: #000;
    color: #eee;
}

.fixed-nav ul {
    padding: 0;
}

.fixed-nav img {
    vertical-align: middle;
}

.menu-icon{
    margin-right: 5px;
}

main {
    margin-top: 55px;
}
<nav class="fixed-nav">
        <ul>
            <li><a href="#"><img src="image/cofee.png" height="30" class="menu-icon"/>Cofee</a></li>
            <li><a href="#"><img src="image/koki.png" height="30" class="menu-icon"/>Restaurant</a></li>
            <li><a href="#"><img src="image/beer.png" height="30" class="menu-icon"/>Drinks & Nightlife</a></li>
        </ul>
    </nav>

答案 1 :(得分:1)

您已.fixed-nav填充10px。删除左侧的填充以解决问题。

使用flexbox ...

替代布局的方法

.fixed-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: #ddd;
  white-space: nowrap;
  height: 50px;
  box-sizing: border-box;
  box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16), 0px 3px 6px rgba(0, 0, 0, 0.23);
}

.fixed-nav ul,
.fixed-nav li,
.fixed-nav a {
  display: flex;
}

.fixed-nav ul {
  height: 50px;
  margin: 0;
}

.fixed-nav a {
  text-decoration: none;
  text-transform: uppercase;
  color: #333;
  font-family: arial;
  align-items: center;
  padding: 0 10px;
}

.fixed-nav a:hover {
  background-color: #000;
  color: #eee;
}

.fixed-nav ul {
  padding: 0;
}

.fixed-nav img {
  vertical-align: middle;
}

.menu-icon {
  margin-right: 5px;
}

main {
  margin-top: 55px;
}
<nav class="fixed-nav">
  <ul>
    <li>
      <a href="#"><img src="image/cofee.png" height="30" class="menu-icon" />Cofee</a>
    </li>
    <li>
      <a href="#"><img src="image/koki.png" height="30" class="menu-icon" />Restaurant</a>
    </li>
    <li>
      <a href="#"><img src="image/beer.png" height="30" class="menu-icon" />Drinks & Nightlife</a>
    </li>
  </ul>
</nav>