I need to place a button, with an icon, an input so I tried the HTML:
(JSFiddle Example: 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>
With the following 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;
}
But this does not place the button inside the input.
How can this be done?
All you need to do is to add bottom: 8px;
to the button so it is moved up by 8px
, visually into the input box.
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>
Updated JSFiddle: https://jsfiddle.net/zup3b24e/14/
A simpler way to build an input form with font awesome inside if you want to go with this direction
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="">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.