【问题标题】:Search Form in Navigation Bar is not Aligned Correctly导航栏中的搜索表单未正确对齐
【发布时间】:2020-05-11 17:21:31
【问题描述】:

我正在创建一个带有搜索表单的引导导航栏,但是当我将搜索表单放入我的导航时,导航项没有正确对齐,因为表单转到顶部而文本项菜单转到底部。

这里演示一下问题:

html,
body {
  background: #f7f7f8
}

.text-white {
  color: #fff !important;
}

section.header {
  padding: 90px 0;
}

.logo {
  line-height: 60px;
  /*position: fixed;*/
  float: left;
  margin: 0 46px;
  color: #FFF;
  font-weight: bold;
  font-size: 20px;
  letter-spacing: 2px;
}

nav {
  /*display: flex;*/
  background: #099cec;
  height: 64px;
  color: #FFF;
  width: 100%;
  line-height: 60px;
}

nav ul {
  line-height: 60px;
  list-style: none;
  background: rgba(0, 0, 0, 0);
  overflow: hidden;
  color: #FFF;
  padding: 0;
  text-align: right;
  margin: 0;
  padding-right: 40px;
  transition: 1s;
}

nav.black ul {
  background: #000;
}

nav ul li {
  display: inline-block;
  padding: 0 40px;
  ;
}

nav ul li a,
nav ul li a:hover {
  text-decoration: none;
  color: #FFF;
  font-size: 16px;
}

.menu-icon {
  line-height: 60px;
  width: 100%;
  background: #000;
  text-align: right;
  box-sizing: border-box;
  padding: 15px 24px;
  cursor: pointer;
  color: #fff;
  display: none;
}

@media(max-width: 786px) {
  .logo {
    /*position: fixed;*/
    color: #FFF;
    top: 0;
    margin-top: 16px;
  }
  nav ul {
    max-height: 0px;
    background: #000;
  }
  nav.black ul {
    background: #000;
  }
  .showing {
    max-height: 34em;
  }
  nav ul li {
    box-sizing: border-box;
    width: 100%;
    padding: 24px;
    text-align: center;
  }
  .menu-icon {
    display: block;
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

</head>

<body>

  <!-- Navigation -->
  <!-- Static navbar -->
  <header>
    <nav>
      <div class="menu-icon">
        <i class="fa fa-bars fa-2x"></i>
      </div>
      <div class="logo">
        <!-- <img src="mktlogo.jpg"> -->
        Private Package
      </div>
      <div class="menu">
        <ul>

          <li>

            <div class="form-group has-feedback">

              <input type="text" class="form-control" id="inputDefault25">
              <span class="fa fa-search form-control-feedback"></span>
            </div>
          </li>
          <li><a href="#">Contact</a></li>
          <li><a href="#">Contact</a></li>
          <li><a href="#">Contact</a></li>
        </ul>
      </div>
    </nav>
  </header>
  <!-- /Navigation -->




  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>

</html>

看,右边的每一个表格和项目菜单都没有在正确的位置。

这有什么问题?我该如何纠正?谢谢

【问题讨论】:

  • 导航栏也需要引导类:getbootstrap.com/docs/3.4/components/#navbar.
  • @wazz,谢谢,我将.navbar 类添加到&lt;nav&gt;,但仍然无法正常工作。
  • 还有很多要更新的。阅读整个部分并与您的部分进行比较。

标签: html css twitter-bootstrap-3


【解决方案1】:

搜索图标缺少 CSS。因此,与菜单项相比,它使行高更多。下面的 CSS 工作正常。

.form-group {
    position: relative;
}
.form-control-feedback {
    position: absolute;
    z-index: 2;
    display: block;
    width: 2.375rem;
    height: 2.375rem;
    line-height: 2.375rem;
    text-align: center;
    pointer-events: none;
    color: #aaa;
    top: 0;
    left: auto;
    right: 0;
}

【讨论】:

  • 你的问题不清楚你在问什么。尝试添加更多代码以帮助其他人理解。
【解决方案2】:

您的 CSS 唯一缺少的是:

.form-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    • 2014-01-16
    • 2015-03-16
    相关资源
    最近更新 更多