html - 无法对齐搜索栏旁边的按钮

标签 html css button bootstrap-4

我正在尝试将搜索栏与下拉按钮对齐。我试过对齐它们,但没有用。这两个按钮也位于容器中,因此搜索栏是容器宽度的 100%。我也试过左对齐、右对齐和居中对齐。我还将按钮的显示更改为“flex”。

我当前的按钮看起来是这样的:-

currentui

.has-search .form-control {
    padding-left: 38px;
}

.has-search .form-control-feedback {
    position: absolute;
    z-index: 2;
    display: flex;
    width: 38px;
    height: 38px;
    line-height: 38px;
    text-align: center;
    pointer-events: none;
    color: #aaa;
}
 <!DOCTYPE html>
<html lang="en">
    <head>
        <title>sample</title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="css/mystyle.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
        <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
        <script src="js/app.js"></script>
        <script src="js/restaurants.js"></script>
    </head>
<body onload="getRestaurantData()">
        <!-- This is where top navigation html codes is -->
        <div w3-include-html="top-navigation.html"></div>
        <!-- This is the container that holds the initial message, heading, and movies -->



        <div class="container">
        <!-- The message will be shown when the page loads and will
        disappear after the movies are loaded -->



            <div class="dropdown">
                    <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Select cuisine
                    <span class="caret"></span></button>
                    <ul class="dropdown-menu">
                      <li><a href="#">HTML</a></li>
                      <li><a href="#">CSS</a></li>
                      <li><a href="#">JavaScript</a></li>
                    </ul>
            </div>

            <div class="input-group">
              <input type="text" class="form-control" placeholder="Search this blog">
              <div class="input-group-append">
                <button class="btn btn-secondary" type="button">
                  <i class="fa fa-search"></i>
                </button>
              </div>
            </div>
            <br><br>


            <!-- Displays thumbnails of the movies here -->
            <div id="restaurantsTable" class="row"></div>
        </div>
        <br><br>
        <!-- Include footer here -->
        <div w3-include-html="footer.html"></div>
    </body>
<script src="js/w3.js"></script>
<script>
        //to bring in other HTML on the fly into this page
        w3.includeHTML();
</script>
</html>

最佳答案

像这样更改 HTML 代码

<div class="container">
        <!-- The message will be shown when the page loads and will
        disappear after the movies are loaded -->

<div class="d-flex"> /*Changes Here*/
    <div class="dropdown col"> /*Changes Here*/
                    <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Select cuisine
                    <span class="caret"></span></button>
                    <ul class="dropdown-menu">
                      <li><a href="#">HTML</a></li>
                      <li><a href="#">CSS</a></li>
                      <li><a href="#">JavaScript</a></li>
                    </ul>
            </div>

            <div class="input-group col-12 flex-fill"> /*Changes Here*/
              <input type="text" class="form-control" placeholder="Search this blog">
              <div class="input-group-append">
                <button class="btn btn-secondary" type="button">
                  <i class="fa fa-search"></i>
                </button>
              </div>
            </div>
            </div>


            <!-- Displays thumbnails of the movies here -->
            <div id="restaurantsTable" class="row"></div>
        </div>

https://jsfiddle.net/lalji1051/eajpcuh3/2/

关于html - 无法对齐搜索栏旁边的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59853349/

相关文章:

javascript - 如何获得CSS操作图像的高度?

javascript - ng-show 的 Angular 初始转换,使用 $timeout 和 $compile

javascript - 在页面加载时随机定位 div

Python-让按钮随机改变位置

html - 如何在更改边框半径的同时保持 HTML <button> 的背景颜色?

javascript - 在javascript中获取IST时间

javascript - 如何在背景横幅上添加链接?

html - CSS 选择器和伪类

javascript - 使用 jQuery 单击 anchor 标记时 div 内容不隐藏

button - 如何使用fabric.Textbox 类覆盖在fabric js 中创建自定义类?