【问题标题】:html form input text and submit on same linehtml表单输入文本并在同一行提交
【发布时间】:2021-02-13 01:03:02
【问题描述】:

我创建了一个表单。在那,我需要在同一行添加文本框和提交按钮。

<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>

【问题讨论】:

    标签: html css forms textbox submit


    【解决方案1】:

    看起来你正在使用引导程序。

    将这两个元素包装在 row 中并使用 column 结构。必要时调整填充/边距。有关更多信息,请查看网格系统上的引导文档: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>
    

    这些列需要加起来最多 12 个,因此您可以随意更改它。

    col-lg-4 用于输入
    col-lg-8 按钮

    或者你想这样做。如果您需要更多地调整间距,我认为在 Bootstrap 4 中有一个用于控制元素填充的类:

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

    例如,您可以将 p-0 类添加到按钮,它会消除元素上的填充

    【讨论】:

    • 感谢您的帮助。是工作。文本框并立即在同一行提交。但它们之间有空间。如何解决?
    • 请将我的答案标记为解决方案。你应该能够通过更新来解决这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 2017-11-23
    • 2016-02-20
    • 2016-12-04
    • 2011-06-17
    • 2016-02-07
    • 1970-01-01
    相关资源
    最近更新 更多