导航栏中的搜索表单未正确对齐

问题描述 投票:0回答:2

我正在使用搜索表单创建引导导航栏,但是当我将搜索表单放入导航中时,导航表单的顶部和文本菜单的底部都无法正确对齐导航项。

这里演示问题:

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>

enter image description here

请参见,右侧的每个表单和项目菜单都没有位于正确的位置。

这怎么了?我该如何纠正?谢谢

html css twitter-bootstrap-3
2个回答
0
投票

您的CSS唯一缺少的是:

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

0
投票

搜索图标缺少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;
}
© www.soinside.com 2019 - 2024. All rights reserved.