bootstrap 4

时间:2017-05-14 09:44:57

标签: css css3 flexbox bootstrap-4 twitter-bootstrap-4

这是我第一次使用bootstrap 4而且我认为它应该很容易垂直对齐元素,因为我读到任何地方flex是垂直对齐元素最简单的事情。

问题: 我正在努力将我的表单元素垂直对齐到导航栏中。一旦我为文本输入元素指定了不同的字体大小,它就会变小​​并且不再垂直对齐:enter image description here

我的HTML:

<nav class="navbar navbar-toggleable-md py-3 navbar-dark">
    <div class="container">
        <div class="d-flex justify-content-between"><a class="navbar-brand" href="/">TMS</a><button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#bd-main-nav" aria-controls="bd-main-nav" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button></div>
        <div class="navbar-collapse collapse" id="bd-main-nav" aria-expanded="false">
            <ul class="nav navbar-nav right-spacer">
                <li class="nav-item"><a class="nav-item nav-link" href="/features">Features</a></li>
                <li class="nav-item"><a class="nav-item nav-link" href="/features">Demo</a></li>
                <li class="nav-item"><a class="nav-item nav-link" href="/pricing">Pricing</a></li>
                <li class="nav-item"><a class="nav-item nav-link" href="/contact">Contact</a></li>

                <form class="navbar-form" role="search"><input class="header-search-input form-control" type="text" placeholder="Search projects" name="q"></form>
                <li class="nav-item"><a class="nav-item nav-link" href="/login/">Sign in</a></li>
            </ul>
        </div>
    </div>
</nav>

自定义CSS:

.navbar-dark .header-search-input {
    background-color: #fafafa;
    font-size: .7rem;
}

小提琴: https://jsfiddle.net/qo33wf3d/(调整输出窗口大小,否则会显示空响应版本)

1 个答案:

答案 0 :(得分:1)

使用表单上的my-auto课程...

       <form class="navbar-form my-auto" role="search">
            <input class="header-search-input form-control" type="text" placeholder="Search projects" name="q">
       </form>

http://www.codeply.com/go/Zo1Ci90MbH