I have been attempting to center elements within a div
using the sticky-top
class, but so far, I have not been successful. I have tried using the following classes:
d-flex justify-content-center align-items-center flex-column
body, html {
height: 100%;
}
#element-1 {
background: lightgray;
height: 1000px;
overflow: auto;
}
#element-2 {
background: gray;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="container-fluid h-100">
<div class="row">
<div class="col-8" id="element-1">
Some Content
</div>
<div class="col-4" id="element-2">
<div class="sticky-top">
<div class="d-flex justify-content-center align-items-center flex-column">
<div>I should be centered vertically</div>
</div>
</div>
</div>
</div>
</div>
Despite my efforts, the element is not centered vertically as desired. My goal is to have the elements centered vertically and not in line with each other.
Thank you in advance.
Edit: Here is a visual representation of my desired outcome: