'bootstrap horizontally align elements
I can't figure out why my button isn't aligned with the input field. I use bootstrap as example
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="row">
<div class="d-flex flex-row">
<div class="col-8">
<div class="form-group">
<label>Search:</label>
<input type="text" name="name" id="search-id" autocomplete="off" class="form-control" placeholder="Required" />
</div>
</div>
<div class="col-1">
<div class="">
<button class="btn btn-primary" onclick="load();">Load</button>
</div>
</div>
</div>
</div>
Solution 1:[1]
simply move the label outside of the flex-container:
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<label>Search:</label>
<div class="row">
<div class="d-flex flex-row">
<div class="col-8">
<div class="form-group">
<input type="text" name="name" id="search-id" autocomplete="off" class="form-control" placeholder="Required" />
</div>
</div>
<div class="col-1">
<div class="">
<button class="btn btn-primary" onclick="load();">Load</button>
</div>
</div>
</div>
</div>
Solution 2:[2]
Here is the Update markup
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="container">
<p>Search</p>
<div class="row d-flex justify-content-flex-end">
<div class="col-8">
<div class="form-group">
<input type="text" name="name" id="search-id" autocomplete="off" class="form-control" placeholder="Search Here" />
</div>
</div>
<div class="col-1">
<div class="">
<button class="btn btn-primary" onclick="load();">Load</button>
</div>
</div>
</div>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tacoshy |
| Solution 2 | Momin |

