Flex Column forcibly hides the initial items of the flexbox

I have a Sidebar which is built using FlexBox column layout as shown below:

.SideBarContainer {
  // flex-grow: 1;
  width: 100%;
  height: 100%;
  // display: flex;
  // flex-direction: column;
  padding: 0.5rem 1rem;
  align-items: center;
  justify-content: space-evenly;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: $font-family;
}

And looks like:

Flex Container

This is when I comment out flex layout (ideally which I want to keep). But when I enable flex layout as shown below:

.SideBarContainer {
  // flex-grow: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0.5rem 1rem;
  align-items: center;
  justify-content: space-evenly;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: $font-family;
}

for some reason it forces the image to be shifted to top and it can't be scrolled to the view: enter image description here

One way would be to get rid of flexbox and somehow align the items to center but I am more interested in understanding how can I achieve the same with FlexBox and what exactly it is that's pushing the image to cut off when flexbox is applied.


Solution 1:

I have created this html code and CSS for you:

.main {
  width: calc(100%/3 + 60px);
  font-family: 'Jost', sans-serif;
}

.SideBarContainer {
  display: flex;
  flex-direction: column;
}

.name {
  margin: 0;
  font-size: 30px;
}

.desig {
  color: #bcbcbc;
  font-weight: 600;
}

.profile-img {
  border-radius: 100%;
  height: 100px;
  width: 100px;
  object-fit: cover;
}

.btn {
  background-color: #f5f5f5;
  color: #000000;
  display: inline-block;
  text-align: center;
  text-decoration: none;
  font-size: 16px;
  padding: 4px 20px;
  margin: 10px 0;
  width: fit-content;
  box-shadow: 0 0 5px 0 rgb(0 0 0 / 20%);
}

.btn.dark {
  background-color: #000;
  color: #f3ff26;
  text-transform: capitalize;
  font-weight: 400;
  font-size: 18px;
  width: calc(100% - 60px);
  border-radius: 8px;
  box-shadow: 0 0 5px 0 rgb(0 0 0 / 20%);
}
<div class="main">
  <div class="SideBarContainer">
    <img src="https://via.placeholder.com/150x150" class="profile-img" />
    <h6 class="name">Rampy sharma</h6>
    <span class="desig">Individual Singer</span>
    <a href="javscript:void(0);" class="btn">Edit</a>
    <p>It is a long established fact that a reader will be distracted by the readable that it has a more-or-less normal distribution of letters, as opposed to using 'Content here.</p>
    <a href="javscript:void(0);" class="btn dark">portfolio</a>
  </div>
</div>