HTML Bootstrap搜索栏

时间:2017-07-26 17:03:48

标签: html css twitter-bootstrap

我试图为ebay类型的网站制作搜索栏,但出于某种原因,提交按钮会获取上一个资产的列大小,也会直接在此资产下。 enter image description here

CODE



<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<body>
	<div class="container">
		<form class="form">
			
			<!-- SEARCH -->
			<div class="form-group">
			<div class="col-sm-6 form-group NoPadding"> 
					<input type="text" class="form-control">
			</div>
			
			<!-- CATEGORIES -->
			<div class="col-sm-2 form-group NoPadding"> 
				<select name="Categories" class="form-control">
					<option value="0">All Categories</option>
					<option value="1">Electronics</option>
					<option value="2">Food</option>
					<option value="3">Furniture</option>
			</div>
			
			<!-- BUTTON -->
			<div class="col-sm-1 form-group NoPadding"> 
				<input type="submit" class="form-control">
			</div>
			
	    	</form>
	     </div> 
    </body>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:3)

您忘了关闭<select>。您可以减少border-radius输入以使其更接近ebay。

.NoPadding{
padding:0 !important;
}

input,select{
border-radius:1px !important
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<body>
	<div class="container">
		<form class="form">
			
			<!-- SEARCH -->
			<div class="form-group">
			<div class="col-sm-6 form-group NoPadding"> 
					<input type="text" class="form-control">
			</div>
			
			<!-- CATEGORIES -->
			<div class="col-sm-3 form-group NoPadding"> 
				<select name="Categories" class="form-control">
					<option value="0">All Categories</option>
					<option value="1">Electronics</option>
					<option value="2">Food</option>
					<option value="3">Furniture</option>
          </select>
			</div>
			
			<!-- BUTTON -->
			<div class="col-sm-2 frm-group "> 
				<input type="submit" class="form-control btn-primary">
			</div>
			
	    	</form>
	     </div> 
    </body>

答案 1 :(得分:2)

您根本没有关闭selectdiv.form-group

另外,我建议添加col-md-#,其中#是数字。

请点击此处查看已关闭的代码:https://jsfiddle.net/8z7cL5x0/

答案 2 :(得分:0)

尝试将列包装在带有“row”类的div中:

<body>
  <div class="container">
   <div class = "row">
     <form class="form">

      <!-- SEARCH -->
      <div class="form-group">
      <div class="col-sm-6 form-group NoPadding"> 
            <input type="text" class="form-control">
      </div>

      <!-- CATEGORIES -->
      <div class="col-sm-2 form-group NoPadding"> 
        <select name="Categories" class="form-control">
            <option value="0">All Categories</option>
            <option value="1">Electronics</option>
            <option value="2">Food</option>
            <option value="3">Furniture</option>
      </div>

      <!-- BUTTON -->
      <div class="col-sm-1 form-group NoPadding"> 
        <input type="submit" class="form-control">
      </div>

     </form>
    </div>
 </div> 
</body>