Html Twitter Bootstrap:在导航栏中选择元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13411208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:54:18  来源:igfitidea点击:

Twitter Bootstrap: Select element in Nav bar

csshtmltwitter-bootstrap

提问by Jeff Lange

I am having issues with <select>elements lining up in a bootstrap nav bar. I want the text from "Search for" all the way to the "Go!" button to be vertically aligned. It looks as if the button and selection elements are the same height, so I want them to be flush on the top and bottom.

<select>在引导程序导航栏中排列元素时遇到问题。我想要从“搜索”一直到“去!”的文本。按钮垂直对齐。看起来按钮和选择元素的高度相同,所以我希望它们在顶部和底部齐平。

Here's the code:

这是代码:

<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
        <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </a>
        <a class="brand" href="#">Project</a>
        <div class="nav-collapse collapse">
            <ul class="nav">
                <li class="active"><a href="#"><i class="icon-home"></i> Home</a></li>
            </ul>
            <form class="navbar-search pull-right">
                <div>Search for 
                    <select class="span2">
                        <option>Things</option>
                    </select> in 
                    <select class="span2">
                        <option>City, NY</option>
                    </select>
                    <button type="button" class="btn btn-primary">Go!</button>
                    </div>
                </form>
            </div><!--/.nav-collapse -->
        </div>
    </div>
</div>

Here's a jsFiddle with an example. http://jsfiddle.net/jefe317/EjS6f/2/

这是一个带有示例的 jsFiddle。http://jsfiddle.net/jefe317/EjS6f/2/

Both Firefox and Chrome show similar results

Firefox 和 Chrome 显示相似的结果

enter image description here

在此处输入图片说明

采纳答案by David Fritsch

Rohit's answer kind of works but can leave the text off center a little. You can also remove the margin-bottom from the select:

Rohit 的回答有点奏效,但可以将文本稍微偏离中心。您还可以从选择中删除边距底部:

select[class*="span"] {
    margin-bottom: 0;
}

That should even everything out.

那应该甚至一切都出来了。

http://jsfiddle.net/EjS6f/5/

http://jsfiddle.net/EjS6f/5/

回答by WarrenV

I had a similar problem but I fixed it with:

我有一个类似的问题,但我修复了它:

<select class="span2 navbar-btn">
    <option>Things</option>
</select> in 
 <select class="span2 navbar-btn">
   <option>City, NY</option>
</select>
<button type="button" class="btn btn-default navbar-btn">Go!<button>

回答by Rohit Azad

Demo

演示

Hi @Jeff LangeNow define your buttonmargin-top:0;and add tovertical-align:top;

@Jeff Lange现在定义您的按钮margin-top:0;添加到vertical-align:top;

As like this

像这样

.btn.btn-primary{
margin-top:0 !important;
    vertical-align: top;
}

Demo

演示