Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Not able to understand why the given CSS is not working

This is basically a youtube clone which i am working on. The contents of the sidebar should be in the middle. But i am not able to bring the contents to the middle.

enter image description here

.sidebar {
  background-color: rgb(175, 146, 146);
  width: 100px;
  display: flex;
  flex-direction: column;
  position: fixed;
  align-items: center;
  bottom: 0;
  left: 0;
  top: 72px;
  padding-top: 15px;
}

p {
  margin: 0;
  margin-bottom: 24px;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  font-size: 12px;
}

.home-img {
  width: 24px;
}

.home {
  width: 100%;
}

.explore-img {
  width: 24px;
}

.explore {
  width: 100%;
}

.subscriptions-img {
  width: 24px;
}

.subscriptions {
  width: 100%;
}

.originals-img {
  width: 24px;
}

.originals {
  width: 100%;
}

.youtube-music-img {
  width: 24px;
}

.youtube-music {
  width: 100%;
}

.library-img {
  width: 24px;
}

.library {
  width: 100%;
}
<div class="sidebar">
  <div class="home">
    <img class="home-img" src="https://dummyimage.com/20x20/000/fff" alt="">
    <p class="hp">Home</p>
  </div>
  <div class="explore">
    <img class="explore-img" src=".https://dummyimage.com/20x20/000/fff" alt="">
    <p class="ep">Explore</p>
  </div>
  <div class="subscriptions">
    <img class="subscriptions-img" src="https://dummyimage.com/20x20/000/fff" alt="">
    <p class="sp">Subsriptions</p>
  </div>
  <div class="originals">
    <img class="originals-img" src="https://dummyimage.com/20x20/000/fff" alt="">
    <p class="op">Originals</p>
  </div>
  <div class="youtube-music">
    <img class="youtube-music-img" src="https://dummyimage.com/20x20/000/fff" alt="">
    <p class="yp">Youtube Music</p>
  </div>
  <div class="library">
    <img class="library-img" src="https://dummyimage.com/20x20/000/fff" alt="">
    <p class="lp">Library</p>
  </div>

</div>

I am expecting the sidebar to look like below :
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You must use display: flex with flex-direction: column and align-items: center in your div children of .sidebar like this:

.sidebar{
    background-color:rgb(175, 146, 146);
    width: 100px;
    display: flex;
    flex-direction: column;
    position: fixed;
    align-items: center;
    bottom: 0;
    left: 0;
    top:72px;
    padding-top: 15px;
}
p{
    margin: 0;
    margin-bottom: 24px;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    font-size: 12px;
}
.home-img{
    width: 24px;
}
.home{
    width: 100%;
    display:flex;
    flex-direction: column;
    align-items: center;
}
.explore-img{
    width: 24px;
}
.explore{
    width: 100%;
    display:flex;
    flex-direction: column;
    align-items: center;
}
.subscriptions-img{
    width: 24px;
}
.subscriptions{
    width: 100%;
    display:flex;
    flex-direction: column;
    align-items: center;
}
.originals-img{
    width: 24px;
}
.originals{
    width: 100%;
    display:flex;
    flex-direction: column;
    align-items: center;
}
.youtube-music-img{
    width: 24px;
}
.youtube-music{
    width: 100%;
    display:flex;
    flex-direction: column;
    align-items: center;
}
.library-img{
    width: 24px;
}
.library{
    width: 100%;
    display:flex;
    flex-direction: column;
    align-items: center;

}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading