将Bootstrap 4按钮与Angular 6中页面的其他内容对齐

时间:2018-08-30 15:38:45

标签: html css angular bootstrap-4

我正在使用引导程序4,其中按钮未对齐.... enter image description here

我通过写一些CSS来解决此问题

.btn-success, .btn-danger, .btn-primary {
margin-left: 30px;
margin-right: -15px;

}

enter image description here

HTML

<div class="row">
<div class="col-xs-12">
<form>
  <div class="row ml-auto">
    <div class="col-sm-5 form-group">
      <label for="name">Name</label>
      <input type="text" id="name" class="form-control">
    </div>
    <div class="col-sm-2 form-group">
      <label for="amount">Amount</label>
      <input type="number" id="amount" class="form-control">
    </div>
  </div>
  <div class="row">
    <div class="col-xs-12">
      <button class="btn btn-success" type="submit">Add</button>
      <button class="btn btn-danger" type="submit">Delete</button>
      <button class="btn btn-primary" type="submit">Clear</button>
    </div>
  </div>
</form>
</div>
</div>

我使用引导程序类ml-auto,向右浮动,但没有任何方法可以解决我的问题。我相信有解决这个问题的更好方法...

2 个答案:

答案 0 :(得分:1)

尝试:

class="text-right"

并遵循文档中Bootstrap grid.的规则。

  

“行是列的包装器...在网格布局中,内容必须为   放置在列中,并且只有列可以是的直接子代   行。”

<container>
  <row>
    <col-12>
      <card/>
    </col>
    <col-12>
      <card/>
    </col>
    <col-12>
      <card/>
    </col>
  </row>
</container>

<container>
  <row>
    <col-12>
      <card/>
    </col>
  </row>
  <row>
    <col-12>
      <card/>
    </col>
  </row>
  <row>
    <col-12>
      <card/>
    </col>
  </row>
</container>

答案 1 :(得分:0)

您可以添加一个父级flex-container并添加CSS属性justify-content: spacebetween,如下所示:

.flex-container {
  display: flex;
  width: 150px;
  justify-content: space-between;
}
<div class="row">
<div class="col-xs-12">
<form>
  <div class="row ml-auto">
    <div class="col-sm-5 form-group">
      <label for="name">Name</label>
      <input type="text" id="name" class="form-control">
    </div>
    <div class="col-sm-2 form-group">
      <label for="amount">Amount</label>
      <input type="number" id="amount" class="form-control">
    </div>
  </div>
  <div class="row">
    <div class="flex-container col-xs-12">
      <button class="btn btn-success" type="submit">Add</button>
      <button class="btn btn-danger" type="submit">Delete</button>
      <button class="btn btn-primary" type="submit">Clear</button>
    </div>
  </div>
</form>