2016-08-01 70 views
-3

如何将一个按钮添加到搜索字段,使其看起来像这样?如何在搜索栏左侧添加按钮?

enter image description here

这里是我的代码:

<div id="search"> 
    <div class="container"> 
    <h1>Search U.K. house price data</h1> 
    <form class="has-success has-feedback has-feedback-left"> 
     <label class="control-label sr-only" for="inputSearch">Search U.K. house price data</label> 
     <input class="form-control" type="text" id="inputSearch" placeholder="Enter a postcode, street or address"> 
     <span class="glyphicon glyphicon-search form-control-feedback"></span> 
     <button class="btn" type="submit">SEARCH</button> 
    </form> 
    </div> 
</div> 

这里我得到了什么使用此代码:

enter image description here

.btn { 
position:absolute; 
top: 20px; 
right: 100px; 

}

+0

分享你已经试过 – Zentryn

+0

.btn {CSS的 \t的位置是:绝对的; \t top:20px; \t right:100px; } – Ravdan

+0

从右向左改变。 – Kyle

回答

0

只需设置表格的高度,以搜索栏的相同height,并添加position:relative

还那么你就需要改变你的按钮,顶部的值。

表单是您的按钮的父元素,绝对元素用于监视最靠近父亲的父亲position:relative,并将其本身绝对定位在此父母的容器内。

+0

如果你不介意,请写下代码。 – Ravdan

+0

我可以修复你的代码,如果你发布表单的完整CSS,而不仅仅是按钮部分。我只会创建jsfiddle并为您指出更改。 :) –

+0

我如何做到这一点:#搜索表格{ \t height:100px; } #搜索表格输入{ \t height:60px; \t位置:相对; \t border-radius:30px; \t max-width:970px; } – Ravdan

0

它可以像 jsfiddle

CSS

.btn { 
position:absolute; 
top: 5px; 
right: 10px; 
padding-top: 0px; 
padding-bottom: 1px; 
border-radius: 18px;} 
.form-control-feedback{ 
left:0; 
} 
#inputSearch{ 
    padding-left: 30px; 
    border-radius: 18px; 
} 

HTML

<div id="search"> 
<div class="container"> 
<h1>Search U.K. house price data</h1> 
<form class="has-success has-feedback has-feedback-left"> 
    <label class="control-label sr-only" for="inputSearch">Search U.K. house price data</label> 
    <input class="form-control" type="text" id="inputSearch" placeholder="Enter a postcode, street or address"> 
    <span class="glyphicon glyphicon-search form-control-feedback"></span> 
    <button class="btn" type="submit">SEARCH</button> 
    </form> 
</div> 
</div> 
+0

它仍然显示在底部 – Ravdan

+0

什么是与它的问题的探析? – Ravdan

+0

它可能与另一个冲突风格。所以我更新了jsfiddle by make position,top and right!important https://jsfiddle.net/shady_youssery/0kwax0vp/3/ –

相关问题