我创建了一个响应式Bootstrap标题,左侧是Name,搜索栏和右下角的下拉列表。现在我尝试在搜索栏的左侧添加一个按钮,但无法进行..
Js小提琴 https://jsfiddle.net/Lucy1/qn0r10th/4/
HTML代码 ..
<nav class="navbar navbar-default navbar-fixed-top" id="header">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar1">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html" class="navbar-brand" id="icon"><b>Sample Name</b></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar1">
<ul class="nav navbar-nav navbar-right" id="navbar1right">
<li class="dropdown" id="subheader">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" id="dropA">
<li><a href="#">Action</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right" role="search" id="navBarSearchForm" type=get action="myindex.html">
<div class="input-group" id ="searchA">
<button onclick="storeYourStuff()" id="button_top_right" class="btn btn-primary">StoreYourStuff</button>
<input id="wish_title1" type="text" class="form-control" placeholder="Search Website" name="wish_title1"></input>
<span class="input-group-btn">
<button class="btn btn-primary"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</form>
</div>
</div>
</nav>
我试图在表单标记内的搜索栏之前添加一个按钮,但却无法。无法弄清楚我出错的地方..请帮忙
答案 0 :(得分:0)
您的按钮位置错误,需要位于按钮组之外:
工作小提琴:Link
<nav class="navbar navbar-default navbar-fixed-top" id="header">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar1">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html" class="navbar-brand" id="icon"><b>Sample Name</b></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar1">
<ul class="nav navbar-nav navbar-right" id="navbar1right">
<li class="dropdown" id="subheader">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" id="dropA">
<li><a href="#">Action</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right" role="search" id="navBarSearchForm" type=get action="myindex.html">
<button onclick="storeYourStuff()" id="button_top_right" class="btn btn-primary">StoreYourStuff</button>
<div class="input-group" id ="searchA">
<input id="wish_title1" type="text" class="form-control" placeholder="Search Website" name="wish_title1">
<span class="input-group-btn">
<button class="btn btn-primary"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</form>
</div>
</div>
</nav>
答案 1 :(得分:0)
按钮应放在适当的范围内
<form class="navbar-form navbar-right" role="search" id="navBarSearchForm" type=get action="myindex.html">
<div class="input-group" id ="searchA">
<span class="input-group-btn"><button onclick="storeYourStuff()" id="button_top_right" class="btn btn-primary">StoreYourStuff</button></span>
<input id="wish_title1" type="text" class="form-control" placeholder="Search Website" name="wish_title1">
<span class="input-group-btn">
<button class="btn btn-primary"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</form>