How should I put an image below my sidebar menu

Viewed 252

Problem: So my problem is that I am unable to put an image below my sidebar menu (the image is placed on the right side of the sidebar menu). Here have a look for a better understanding of what I am saying:- https://ibb.co/mRtsKdM

I managed to make the sidebar menu responsive but I am unable to put the image below it. Have a look at what I saying:- https://ibb.co/ZxpckyC

@import "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css";

body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

header {
  position: fixed;
  background: #333;
  padding: 20px;
  width: 100%;
  height: 30px;
}

.left_area h3 {
  color: #fff;
  font-size: 30px;
  font-weight: 900;
  margin: 0;
}

.left_area span {
  color: orange;
}

.logout_btn {
  padding: 5px;
  background: aqua;
  float: right;
  margin-top: -30px;
  margin-right: 40px;
  text-decoration: none;
  border-radius: 100px;
  cursor: pointer;
  font-size: 16px;
}

.logout_btn:hover {
  background: aquamarine;
}

.sidebar {
  margin-top: 70px;
  padding-top: 30px;
  position: fixed;
  background: rgb(134, 134, 134);
  width: 260px;
  height: 100vh;
}

.my_profile {
  width: 100px;
  height: 100px;
  border-radius: 100px;
  border: 5px solid orange;
}

.sidebar h4 {
  color: #fff;
  margin-bottom: 2px;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
}

.sidebar h4 span {
  color: aqua;
}

.sidebar a {
  color: #fff;
  display: block;
  line-height: 74px;
  text-decoration: none;
  padding-left: 40px;
  box-sizing: border-box;
  text-align: center;
}

.sidebar a:hover {
  background: orange;
}

.sidebar a {
  padding-right: 50px;
}

.sidebar i {
  padding-right: 10px;
}

.content {
  background: url(images/charles-adrien-fournier-g815W4LH4F8-unsplash.jpg);
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  margin-left: 260px;
  height: 100vh;
}

@media (max-width:768px) {
  .left_area h3 {
    font-size: 23px;
    font-weight: 900;
  }
  .logout_btn {
    margin-top: -28px;
    margin-right: 40px;
    font-size: 14px;
  }
  .sidebar {
    margin-top: 70px;
    padding-top: 30px;
    width: 100%;
    height: 100vh;
  }
  .sidebar a {
    line-height: 92px;
  }
  .sidebar i {
    padding-right: 20px;
  }
  .content {
    position: fixed;
    display: block;
    background: url(images/charles-adrien-fournier-g815W4LH4F8-unsplash.jpg);
    margin-top: 660px;
    height: 100vh;
  }
}
<header>
  <div class="left_area">
    <h3>MY <span>PORTFOLIO</span></h3>
  </div>
  
  <div class="right_area">
    <a href="#" class="logout_btn">Contact Me</a>
  </div>
</header>

<div class="sidebar">
  <center>
    <img src="images/my_image.png" alt="image" class="my_profile">
    <h4>Tejansh <span>Srivastava</span></h4>
  </center>
  
  <a href="#"><i class="fas fa-home"></i><span>Home</span></a>
  <a href="#"><i class="fas fa-info-circle"></i><span>About Me</span></a>
  <a href="#"><i class="fas fa-images"></i><span>Portfolio</span></a>
  <a href="#"><i class="fas fa-id-badge"></i><span>Contact Me</span></a>
</div>

<div class="content"></div>

2 Answers

In HTML you need to change <center> to <div> so you can position the image as you want

<div>
  <img src="images/my_image.png" alt="image" class="my_profile">
  <h4>Tejansh <span>Srivastava</span></h4>
</div>

And the CSS .my_profile class you need to add

.my_profile {
  position: relative;
  top: 0;
  left: 0;
}

And also add padding in the parent element

.sidebar {
  padding: 0 10px;
}

In your HTML code you should change <center> to <div> so that you can reposition your image as per need

I suggest this to be your html code:

<div>
  <img src="images/my_image.png" alt="image" class="my_profile">
  <h4>Tejansh <span>Srivastava</span></h4>
</div>

CSS:

.my_profile {
  position: absolute;
  top: 0;
  left: 0;
}

Also instead of making position: fixed; in the parent element make it position: absolute; .And try to use left and top to change the position instead of margin and padding

Related