mahanthesh
mahanthesh

Reputation: 71

align input tag to bottom inside a div element in bootstrap

How to align input tag to the bottom of the div tag , input tag of the second div with label Amount collected on the date should be aligned to bottom. Tried adding text-alignment-bottom but it is not working.

<div class="row col-sm-12" style="border: thin solid black ">
  <div class="row " margin-top:4px>
    <div class="col-sm-4 col-lg-2">
      <label class="description" for="element_2"> Amount payable on this date </label>
      <input type="number" required="required" class="form-control" name='amountdue' id="amountDue" onkeyup="diffInCollection()">
    </div>
    <div class="col-sm-4 col-lg-2">
      <label class="description" for="element_2">Amount collected on date </label>
      <input type="number" required="required" class="form-control text-bottom " name='collectedamount' align="bottom" id="amountCollected" onkeyup="diffInCollection()">
    </div>
    <div class=" col-sm-4 col-lg-2">
      <label class="description" for="element_2">Shortfall in collections for the day </label>
      <input type="number" required="required" class="form-control" name='shortfall' id="shortfall" value="">
    </div>
  </div>
</div>

input tag of the second div with label Amount collected on the date should be aligned to bottom

Upvotes: 1

Views: 1076

Answers (2)

Nisharg Shah
Nisharg Shah

Reputation: 19542

You can achieve your goal by using flexbox.

USING BOOTSTRAP CLASSES

you need to add d-flex flex-column justify-content-between in your all col-sm-4.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<div class="row col-sm-12" style="border: thin solid black ">
    <div class="row" style="margin-top:4px" >
        <div class="col-sm-4 col-lg-2 d-flex flex-column justify-content-between">
            <label class="description" for="element_2"> Amount payable on this date </label>
            <input type="number" required="required" class="form-control" name='amountdue' id="amountDue" onkeyup="diffInCollection()">
        </div>
        <div class="col-sm-4 col-lg-2 d-flex flex-column justify-content-between">
           <label class="description" for="element_2">Amount collected </label>
           <input type="number" required="required" class="form-control text-bottom"  name='collectedamount' align="bottom" id="amountCollected" onkeyup="diffInCollection()">
       </div>
       <div class=" col-sm-4 col-lg-2 d-flex flex-column justify-content-between">
            <label class="description" for="element_2">Shortfall in collections for the day </label>
            <input type="number" required="required" class="form-control" name='shortfall' id="shortfall" value="">
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

USING CSS CLASSES

I added below CSS in center_input class so your problem will solved

NOTE: DONT ADD CSS INTO col-sm-4 ELSE IN ALL col-sm-4 CLASS APPLY THIS CSS

.center_input {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<div class="row col-sm-12" style="border: thin solid black ">
    <div class="row" style="margin-top:4px" >
        <div class="col-sm-4 col-lg-2 center_input">
            <label class="description" for="element_2"> Amount payable on this date </label>
            <input type="number" required="required" class="form-control" name='amountdue' id="amountDue" onkeyup="diffInCollection()">
        </div>
        <div class="col-sm-4 col-lg-2 center_input">
           <label class="description" for="element_2">Amount collected </label>
           <input type="number" required="required" class="form-control text-bottom"  name='collectedamount' align="bottom" id="amountCollected" onkeyup="diffInCollection()">
       </div>
       <div class=" col-sm-4 col-lg-2 center_input">
            <label class="description" for="element_2">Shortfall in collections for the day </label>
            <input type="number" required="required" class="form-control" name='shortfall' id="shortfall" value="">
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

Upvotes: 1

Anurag Srivastava
Anurag Srivastava

Reputation: 14413

You can add flex properties to .col-sm-4

.col-sm-4 {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row col-sm-12" style="border: thin solid black ">
  <div class="row " margin-top:4px>
    <div class="col-sm-4 col-lg-2">
      <label class="description" for="element_2"> Amount payable on this date </label>
      <input type="number" required="required" class="form-control" name='amountdue' id="amountDue" onkeyup="diffInCollection()">
    </div>
    <div class="col-sm-4 col-lg-2">
      <label class="description" for="element_2">Amount collected on date </label>
      <input type="number" required="required" class="form-control" name='collectedamount' align="bottom" id="amountCollected" onkeyup="diffInCollection()">
    </div>
    <div class="col-sm-4 col-lg-2">
      <label class="description" for="element_2">Shortfall in collections for the day </label>
      <input type="number" required="required" class="form-control" name='shortfall' id="shortfall" value="">
    </div>
  </div>
</div>

Upvotes: 1

Related Questions