編輯:請注意,這個答案適用於Bootstrap v2.3.x. Bootstrap 3已經在本地解決了這個問題(see doc)。
由李某的回答啓發,這是我還挺改進方案(包括追加和前插,最小可能的附加寬度,去掉不必要的風格,汽車高度......)。後引導CSS /減檔包含此:
.input-append.input-block-level,
.input-prepend.input-block-level {
display: table;
}
.input-append.input-block-level .add-on,
.input-prepend.input-block-level .add-on {
display: table-cell;
width: 1%; /* remove this if you want default bootstrap button width */
}
.input-append.input-block-level > input,
.input-prepend.input-block-level > input {
box-sizing: border-box; /* use bootstrap mixin or include vendor variants */
-moz-box-sizing: border-box; /* for Firefox */
display: table; /* table-cell is not working well in Chrome for small widths */
min-height: inherit;
width: 100%;
}
.input-append.input-block-level > input {
border-right: 0;
}
.input-prepend.input-block-level > input {
border-left: 0;
}
使用它像這樣在你的HTML記住,你必須使用a
標籤沒有button
在這種情況下,你的按鈕:
<div class="input-append input-block-level">
<input type="text" />
<a class="btn add-on">click</a>
</div>
編輯:在IE8中,如果您在.input-append.input-block-level > input
中設置display: table
,則儘管採取了焦點,輸入標記也會變得不可編輯。
完全忽略此display:
參數使其在IE8以及當前的Chrome/Safari/Firefox中按預期工作。
看起來不錯!我會試一下! – Astro
我用過這個,但是爲30px的.add-on {}設置了一個設置寬度。我知道這不是最好的解決方案,因爲它會在附加部分的不同內容上打破,但對於一個圖標看起來很不錯。 – Kieran