【问题标题】:Floated div positioning bug in ChromeChrome中的浮动div定位错误
【发布时间】:2013-11-13 02:44:57
【问题描述】:

我正在编写一个相当简单的导航栏,其中包含左右浮动的链接。在组合中还有一个搜索字段,在一个 li 标签内,当包含该标签时,它会将下一个 li 标签垂直向下偏移几个像素(除非您进行测量,否则可能很难看到,但是当它获得一个将鼠标悬停在导航栏的底线上)。它发生在 Chrome (30.0.1599.101) 中,但不是 Safari。

任何人都可以提供帮助或建议解决方法吗?

http://jsfiddle.net/dzSAT/14/

<section id="topnav">
  <div class="navcontainer">
    <nav id="topnav-main">
      <ul>
        <li><a href="/" class="home activelink">Home</a></li>
        <li><a href="/about" class=" ">About</a></li>
      </ul>
    </nav>
    <nav id="topnav-account">
      <ul>
         <li class="searchbar">
          <input type="text" value="Search" />
        </li>
        <li><a href="login" class="store login">Login</a></li>
      </ul>
    </nav>
  </div>
</section>

section#topnav {
  width: 100%;
  height: 4.1875rem;
  position: fixed;
  top: 0;
  z-index: 99;
}
section#topnav .navcontainer {
  width: 25rem;
  margin: 0 auto;
  position: relative;
  top: 1.6875rem;
}
section#topnav nav {
  float: left;
}
section#topnav nav ul {
  margin: 0;
  padding: 0;
}
section#topnav nav ul li {
  display: inline;
  margin-right: 2.1875rem;
}
section#topnav nav ul li a {
  padding-bottom: 1.1875rem;
}
section#topnav ul li.searchbar {
  margin-left: 0;
}
section#topnav ul li.searchbar input {
  width: 4rem;
}
section#topnav nav#topnav-account {
  float: right;
}
section#topnav nav#topnav-account li {
  display: inline;
  margin-right: 0;
  margin-left: 2.1875rem;
  position: relative;
  top: -1px;
}
section#topnav {
  border-bottom: 1px solid #968c83;
  background-color: white;
}
section#topnav nav ul li a {
  color: #968c83;
}
section#topnav nav ul li a:link {
  border-bottom: 5px solid rgba(255, 255, 255, 0);
}
section#topnav nav ul li a:hover, section#topnav nav ul li a.activelink {
  border-bottom: 5px solid #968c83;
}

section#topnav nav ul li.searchbar {
  color: #968c83;
}
section#topnav nav ul li.searchbar input {
  color: #968c83;
}

section#topnav {
  font-size: 0.875rem;
}
section#topnav ul {
  list-style-type: none;
}
section#topnav ul li a {
  text-decoration: none;
}

【问题讨论】:

    标签: html css forms google-chrome


    【解决方案1】:

    这是&lt;input&gt; 上的边距和内边距。

    section#topnav nav ul li.searchbar input {
      color: #968c83;
      margin: 0;
      padding: 0;
    }
    

    作为旁注,虽然我认为您的搜索框不应位于 &lt;li&gt; 内。

    http://jsfiddle.net/dzSAT/16/

    【讨论】:

    • 谢谢!你有什么建议?它应该只是在它自己的浮动 div 中,旁边有一个 ul 和一个 li 吗?
    • 是的,我会浮动一个容器&lt;div&gt;,其中包含&lt;form&gt; 和登录链接。如果登录链接是单独的,那么它是列表项吗?可能不会。
    • 我已经更新了你的小提琴,给你一个快速启动。那里有很多变化,因为我注意到容器上的固定高度和其他一些调整。浏览一下 CSS,看看它是否对您有帮助。 jsfiddle.net/dzSAT/19
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    相关资源
    最近更新 更多