saeef ahmed
saeef ahmed

Reputation: 761

Align Bootstrap 4 Button with other content of the page in Angular 6

I am using bootstrap 4 where Buttons are not aligned ....enter image description here

I fix this issue writing some 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>

I use bootstrap classes ml-auto, float-right but nothing solve my problem. I believe there is better way of solving this problem ...

Upvotes: 0

Views: 1052

Answers (2)

JoelDoryoku
JoelDoryoku

Reputation: 384

Try with:

class="text-right"

And Follow the rules of the Bootstrap grid. From the docs.

"Rows are wrappers for columns... In a grid layout, content must be placed within columns and only columns may be immediate children of rows."

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

or,

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

Upvotes: 1

Oleksandr Bugor
Oleksandr Bugor

Reputation: 1

You may add a parent flex-container and add the CSS propriety justify-content: spacebetween, like this:

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

Upvotes: 0

Related Questions