2016-08-01 49 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/ –

相關問題