在引导网格中对齐textarea和按钮

时间:2019-01-21 19:11:31

标签: html css twitter-bootstrap

在bootstrap 12网格系统中,如何将文本区域和按钮彼此对齐?而且,我的按钮底部有一个烦人的几英寸向上。

我尝试过:

  • 保证金:0自动;

  • 显示:flex;

  • align-items:center;

  • justify-content:center;

  • 显示:内嵌广告

    .center-div-content {
      display: flex;
      align-items: center;
      justify-content: center;
    }
          <div class="col-md-8">
            <input type="text" class="form-control" aria-describedby="sizing-addon1" placeholder="ENTER PROMO CODE">
          </div>
          <div class="col-md-4 center-div-content">
            <input type="submit" class="btn color-white mwc-orange-background-color" name="redeem" value="REDEEM">
          </div>

not aligned

2 个答案:

答案 0 :(得分:2)

将文本区域和按钮包装到行/容器div中就足够了:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>


<div class="container">
    <div class="row">
        <div class="col-md-8 col-8">
            <input type="text" class="form-control" aria-describedby="sizing-addon1" placeholder="ENTER PROMO CODE">
        </div>
        <div class="col-md-4 col-4">
            <input type="submit" class="btn color-white mwc-orange-background-color" name="redeem" value="REDEEM">
        </div>
    </div>
</div>

答案 1 :(得分:1)

使用form row

<form>
  <div class="form-row">
    <div class="col">
        <input type="text" class="form-control" aria-describedby="sizing-addon1" placeholder="ENTER PROMO CODE">
    </div>
    <div class="col">
        <input type="submit" class="btn color-white mwc-orange-background-color" name="redeem" value="REDEEM">
   </div>
  </div>
</form>

https://jsfiddle.net/9b8meg3q/