我对bootstrap很新,我怎样才能将搜索按钮与导航栏中的文本框对齐?我已经尝试了几个小时而没有运气。这就是它的样子:
http://bildr.no/image/TDhPNWZZ.jpeg
这是我的代码:
<div class="collapse navbar-collapse navbar-ex1-collapse">
<div class="col-sm-6 col-md-6">
<form class="navbar-form" role="search" method="get" id="search-form" name="search-form">
<div class="input-group">
@using (Html.BeginForm("Search", "Product", FormMethod.Get)) {
<div class="input-group">
@Html.TextBox("searchString", null, new { id = "txtSearch", @class = "form-control", placeholder = "Søk etter vare..." })
</div>
}
<div class="input-group-btn">
<button class="btn btn-success pull-left" type="submit"><span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form>
</div>
编辑:渲染代码:
<div class="container">
<div class="row">
<div class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Alkohol Mekka</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<div class="col-sm-6 col-md-6">
<form class="navbar-form">
<div class="input-group">
<form action="/Product/Search" method="get">
<input class="form-control" id="txtSearch" name="searchString" placeholder="Søk etter vare..." type="text" value="" />
</form>
<div class="input-group-btn">
<button class="btn btn-success pull-left" type="submit"><span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="/Customer/Register">Registrer</a>
</li>
<li><a href="/Customer/LogIn">Logg Inn</a>
</li>
</ul>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
您的嵌套输入组类的构建不正确。所以你有这个:
<form class="navbar-form" role="search" method="get" id="search-form" name="search-form">
<div class="input-group">!-- it starts here -->
@using (Html.BeginForm("Search", "Product", FormMethod.Get)) {
<div class="input-group">
@Html.TextBox("searchString", null, new { id = "txtSearch", @class = "form-control", placeholder = "Søk etter vare..." })
</div>
}
<div class="input-group-btn">
<button class="btn btn-success pull-left" type="submit"><span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div><!-- and ends here -->
</form>
什么时候应该有这样的东西:
<form class="navbar-form" role="search" method="get" id="search-form" name="search-form">
<div class="input-group">
@using (Html.BeginForm("Search", "Product", FormMethod.Get)) {
@Html.TextBox("searchString", null, new { id = "txtSearch", @class = "form-control", placeholder = "Søk etter vare..." })
}
<div class="input-group-btn">
<button class="btn btn-success pull-left" type="submit"><span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form>
基本上,您需要删除一个.input-group
类,并将整个表单(包含按钮)放在外部input-group
编辑:由于您的未提交代码有可能出现问题(我真的不知道),这里有Bootply向您展示它如何使用默认的html标记