html - 导航栏对齐问题中的搜索框

标签 html css navigation searchbar center-align

嘿,我只是在学习编程,我正在尝试让我的搜索栏始终以导航链接居中,导航链接位于固定导航栏的右侧。我似乎无法让它发挥作用。这是我的 html 和 css。感谢您的帮助!

<div id ="nav">
  <div id ="navigation">
    <container id= "search">
      <form class="form-wrapper cf">
        <form action ='./search.php' method='get'>
          <input type="text" placeholder="" required>
            <button type="submit"><img class= "icon" src="images/search-icon.png"></button>
        </form>
      </container>

      <div>
        <a href="#">Home</a>
        <a href="#">About</a>
        <a href="#">Contact</a>
        <a href="#">Login</a>
      </div>
    </div>  
</div>

还有我的 CSS:

#nav {
  display: block;
  position: fixed;
  top: 0;
  width: 100%;
  height: 28px;
  padding: 12px 0px 0px 0px;background: #4c4c4c; /* Old browsers */
  background: #4c4c4c; /* Old browsers */
  background: -moz-linear-gradient(top, #4c4c4c 0%, #1c1c1c 90%, #131313 100%); /* FF3.6+ */
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(90%,#1c1c1c), color-stop(100%,#131313)); /* Chrome,Safari4+ */
  background: -webkit-linear-gradient(top, #4c4c4c 0%,#1c1c1c 90%,#131313 100%); /* Chrome10+,Safari5.1+ */
  background: -o-linear-gradient(top, #4c4c4c 0%,#1c1c1c 90%,#131313 100%); /* Opera 11.10+ */
  background: -ms-linear-gradient(top, #4c4c4c 0%,#1c1c1c 90%,#131313 100%); /* IE10+ */
  background: linear-gradient(to bottom, #4c4c4c 0%,#1c1c1c 90%,#131313 100%); /* W3C */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 ); /* IE6-9 */

  /* Adds shadow to the bottom of the bar */
  -webkit-box-shadow: 0px 0px 8px 0px #000000;
  -moz-box-shadow: 0px 0px 8px 0px #000000;
  box-shadow: 0px 0px 8px 0px #000000;

  /* Adds the transparent background */
  background-color: rgba(1, 1, 1, 0.8);
  color: rgba(1, 1, 1, 0.8);
}

#nav a { 
  font-size: 12px;
  padding-right: 60px;
  color: white;
    text-decoration: none;
  }

  #nav a:hover {
    color: grey;
  }

  #navigation { 
    display: inline;
    text-align: center;
  }

  #search {
    position: absolute;
    top: 5px;
  }

最佳答案

我会将搜索表单移到导航菜单的中间。看看这个 fiddle :http://jsfiddle.net/DJa25/8/

<div id ="nav">

<div id ="navigation">

<div>
    <a href="#">Home</a>
    <a href="#">About</a>
    <container id= "search">
    <form class="form-wrapper cf">
        <form action ='./search.php' method='get'>
         <input type="text" placeholder="" required>
        <button type="submit"><img class= "icon" src="images/search-icon.png"></button>
    </form>
</container>
    <a href="#">Contact</a>
    <a href="#">Login</a>

</div>

</div>

#search {
  display: inline-block;
 }

关于html - 导航栏对齐问题中的搜索框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20819610/

相关文章:

javascript - 在 css/html 响应式中创建菜单栏

javascript - 从音频标签获取文件对象(HTML5)

css - 在固定高度空间内垂直均匀分布图像

javascript - 使用 jquery 在单击按钮时加载 html 文件时遇到困难

css - Aikau 和 css 要求

php - ZF2 : Active branch for child routes in zend navigation. 怎么办?

html - IE 位置 : absolute 的问题

javascript - 根据另一个 HTML 下拉列表选择设置 HTML 下拉列表的值

javascript - 如何使 $(this) 选择器聚焦于当前元素?

html - 更改导航栏字体