[英]Place button inside input
我需要放置一個帶有圖標的按鈕和一個輸入,所以嘗試了HTML:
(JSFiddle示例: https ://jsfiddle.net/mdmoura/zup3b24e/12/):
<form>
<div class="wrapper">
<input type="text">
<button type="submit">
<i class="fa fa-search"></i>
</button>
</div>
</form>
使用以下CSS:
form {
width: 400px;
}
.wrapper {
position: relative;
}
input {
font-size: 18px;
padding: 10px;
width: 100%;
}
button {
background-color: white;
border: none;
font-size: 24px;
position: absolute;
right: 0;
}
但這不會將按鈕放置在輸入中。
如何才能做到這一點?
您需要做的就是添加bottom: 8px;
到按鈕,以便將其向上移動8px
,直觀地移至輸入框。
button {
background-color: white;
border: none;
font-size: 24px;
position: absolute;
right: 0;
bottom: 8px;
}
form { width: 400px; } .wrapper { position: relative; } input { font-size: 18px; padding: 10px; width: 100%; } button { background-color: white; border: none; font-size: 24px; position: absolute; right: 0; bottom: 8px; }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <form> <div class="wrapper"> <input type="text"> <button type="submit"> <i class="fa fa-search"></i> </button> </div> </form>
更新的JSFiddle: https ://jsfiddle.net/zup3b24e/14/
如果您想朝着這個方向發展,可以使用一種更簡單的方法來構建內部帶有很棒的字體的輸入表單
input[type="text"] { width: 400px; height: 20px; padding: 10px; } input[type="submit"] { font-family: FontAwesome; font-size: 24px; margin-left: -50px; background-color: white; border: none; -webkit-appearance: none; }
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <input type="text"><input type="submit" value="">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.