html form input text and submit on same line

Viewed 115

I create a form. in that, i need to add the textbox and submit button on the same line.

<div class="input-group">
      <form action="searchresult.php" method="post">
         <input type="text" name= "searchtext" class="form-control" placeholder="Search">

         <button class="btn btn-secondary" type="submit">
             <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-search" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
               <path fill-rule="evenodd" d="M10.442 10.442a1 1 0 0 1 1.415 0l3.85 3.85a1 1 0 0 1-1.414 
                1.415l-3.85-3.85a1 1 0 0 1 0-1.415z"/>
               <path fill-rule="evenodd" d="M6.5 12a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zM13 6.5a6.5 
                6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0z"/>
             </svg>
         </button>   
                                       
       </form>
</div>
1 Answers

Looks like you are using bootstrap.

Wrap the two elements in a row and use the column structure. Adjust padding/margins where necessary. For more info, look into the bootstrap documentation on the Grid System: https://getbootstrap.com/docs/4.0/layout/grid/

<div class="input-group">
      <form action="searchresult.php" method="post">
         <div class="row>
            <div class="col-lg-6">
                <input type="text" name= "searchtext" class="form-control" placeholder="Search">
            </div>
            <div class="col-lg-6">
    `            <button class="btn btn-secondary" type="submit">
                    <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-search" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                    <path fill-rule="evenodd" d="M10.442 10.442a1 1 0 0 1 1.415 0l3.85 3.85a1 1 0 0 1-1.414 
                        1.415l-3.85-3.85a1 1 0 0 1 0-1.415z"/>
                    <path fill-rule="evenodd" d="M6.5 12a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zM13 6.5a6.5 
                        6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0z"/>
                    </svg>
                </button> ` 
            </div>
         </div> 
                                       
       </form>
</div>

The columns need to add up to 12, so you can change it however you want to add up.

col-lg-4 for the input
col-lg-8 for the button

or however else you want to do it. If you need to adjust the spacing more, I think there is a class for controlling the padding on an element in Bootstrap 4:

https://getbootstrap.com/docs/4.4/utilities/spacing/

For example you could add class p-0 to the button and it would eliminate the padding on the element

Related