2

I have a search form and I'd like to add the search button inside its right side like this:

enter image description here

Here is the code for my form:

<form action="search.php" method="post" class="index-search-form">
                <input name="search" type="text" class="" placeholder="&#xf002;  What are you looking for?">
                <button name="submit" class="" type="submit">Search</button>
            </form>
PapT
  • 603
  • 4
  • 14
  • 30

3 Answers3

4

If you want to set the button inside the input field. You need to make the button position absolute. And the form position relative and set display: inline-flex or inline-block or initial( For initital you need to adjust the padding top and bottom for button or input field ) . I set a width for the input field so text will be clearly visiable. I ust add a class for input field. If you have any question ask me in comment. Thanks. LiveOnFiddle

form.index-search-form {
  position: relative;
  display: inline-flex;
}

button[name="submit"] {
  position: absolute;
  top: 0;
  right: 0;
}

input.search-box {
  width: 250px;
  font-family: FontAwesome;
  padding: 2px 0;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />

<form action="search.php" method="post" class="index-search-form">
  <input name="search" type="text" class="search-box" placeholder="&#xf002;  What are you looking for?">
  <button name="submit" class="" type="submit">Search</button>
</form>
Baezid Mostafa
  • 2,680
  • 2
  • 14
  • 26
2

Use position and padding to accomplish this effect.

form {
  display: inline-block;
  position: relative;
}
form input {
  padding-right: 4.6em;
}
form button {
  position: absolute;
  top: 0;
  right: 0;
  width: 4.4em;
}
<form action="search.php" method="post" class="index-search-form">
  <input name="search" type="text" placeholder="What are you looking for?">
  <button name="submit" class="" type="submit">Search</button>
</form>
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
0

Do you mean somethink like this?

.index-search-form {
    display: flex;
}

.inputField {
    flex: 1;
}
<form action="search.php" method="post" class="index-search-form">
                <input name="search" type="text" class="inputField" placeholder="&#xf002;  What are you looking for?">
                <button name="submit" class="" type="submit">Search</button>
            </form>
Teshtek
  • 1,212
  • 1
  • 12
  • 20