【问题标题】:How to create a search bar with a search button inside it using bootstrap?如何使用引导程序创建带有搜索按钮的搜索栏?
【发布时间】:2020-07-07 21:20:50
【问题描述】:

我想为我的项目创建一个搜索栏,里面应该有一个像这样的搜索按钮

我的 HTML 如下:

<section id="search-section">
      <div class="container-fluid">
          <h3 class="text-center pt-4">Search for Courses</h3>

          <div class="container-fluid text-center pt-3 outbox">
            <div class='row'>
                <div class='col'>
                    <form class='order-1'>
                        <input type="text" class='form-control d-inline'>
                        <button class='btn btn-md btn-primary d-inline'>Search</button>
                    </form>
                </div>
            </div>
        </div>

      </div>
  </section>

使用的对应的自定义CSS是:

#search-section form {
    border: 1px solid black;
    display: inline-block;
    width: 900px;
    padding-bottom:55px;
    border-radius: 5px;
    background-color:white;
    height:50px;
    box-shadow: 3px 4px 4px rgba(0, 0, 0, .13);


}

#search-section input[type='text'] {
    width:800px;
    height:50px;
    border:none;
}
#search-section button {
    margin-left:10px;
    margin-right:5px;
}

.outbox {
    height: 500px;
}
.form-control:active,
.form-control:focus {
    border: none;
    outline: none;
    box-shadow: none;
}

我的代码的问题是它在大屏幕上运行良好,但在小屏幕设备的屏幕上消失了。我想让它在小屏幕的情况下搜索栏应该堆叠在搜索按钮。

【问题讨论】:

  • 您需要为不同的屏幕尺寸和断点定义媒体查询。 Google
  • 我正在考虑这样做,但认为可能有一些引导类可以使它更容易
  • “但认为可能有一些引导类可以使它更容易” 使用所有自定义 CSS 来调整搜索表单的大小和位置并输入它会更容易只需使用媒体查询

标签: html css twitter-bootstrap bootstrap-4 frontend


【解决方案1】:

您可以最小化自定义 CSS(避免设置静态宽度),然后使用 responsive util classes 定位搜索输入和按钮...

<section id="search-section">
    <div class="container-fluid">
        <h3 class="text-center pt-4">Search for Courses</h3>
        <div class="container-fluid text-center pt-3 outbox">
            <div class='row'>
                <div class='col-lg-8 col-md-10 col-sm-11 mx-auto'>
                    <form class='order-1 d-flex flex-sm-row flex-column align-items-center'>
                        <input type="text" class='border-0 form-control h-100 mt-2 mt-sm-0'>
                        <button class='btn btn-primary mr-sm-1 mt-4 mt-sm-0 flex-fill'>Search</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>

#search-section form {
    border: 1px solid black;
    border-radius: 5px;
    background-color: white;
    height: 50px;
    box-shadow: 3px 4px 4px rgba(0, 0, 0, .13);
}

.outbox {
    height: 500px;
}

.form-control:active,
.form-control:focus {
    border: none;
    outline: none;
    box-shadow: none;
}

https://codeply.com/p/Zl0wdGhJVH

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 2020-02-27
    • 1970-01-01
    • 2015-12-14
    • 2017-11-13
    相关资源
    最近更新 更多