[英]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.