How to fit my sub div on a position fixed parent

Viewed 29

Hi guys, can anyone tell me how can I fit my other div inside the sidebar class? I'm having a problem because my sidebar has a width of 260px and it's also position:fixed. I've tried using width: 100% still not working and I've also set a position relative to my main class side-nav and still not working I think position relative is not working on fixed position. Please help thanks

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500&display=swap');


* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

.sidebar {
    position: fixed;
    top: 0;
    height: 0;
    height: 100%;
    width: 260px;
    background: blue;
}

.sidebar .logo-dtls {
    height: 60px;
    width: 100%;
    display: flex;
    align-items: center;
}


.sidebar .logo-dtls i {
    font-size: 30px;
    color: #fff;
    height: 50px;
    min-width: 78px;
    text-align: center;
    line-height: 50px;
}

.sidebar .logo-dtls .logo {
    font-size: 22px;
    color: #fff;
    font-weight: 600;
}

/* NAV */

.sidebar .side-nav {
    /* background: red; */
    height: 100%;
    padding-top: 30px;
}

.sidebar .side-nav li {
    position: relative;
    list-style: none;
    transition: 0.4s ease all;
}

.sidebar .side-nav li i {
    height: 50px;
    min-width: 78px;
    text-align: center;
    line-height: 50px;
    color: #fff;
    font-size: 20px;
}






/* PROFILE CSS */
.sidebar .profile-c {
    position: fixed;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: black;
}

.sidebar .profile-c .profile-c {
    display: flex;
    align-items: center;
}

.sidebar .profile-c img {
    height: 52px;
    width: 52px;
    object-fit: cover;
    border-radius: 16px;
    margin: 0 14px 0 12px;
    background: red;
    padding: 10px
}

.sidebar .profile-c .profile_n,
.sidebar .profile-c .job_n {
    color: #fff;
    font-size: 18px;
    font-weight: 500;
}

.sidebar .profile-c .job_n {
    font-size: 12px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../materials/fonts/new/fonts.css">
    <link rel="stylesheet" href="../materials/css/style.css">
    <script src="../materials/plugins/jquery-3.6.0.js"></script>
    <link href='https://unpkg.com/boxicons@2.1.2/css/boxicons.min.css' rel='stylesheet'>
    <!-- <script type="text/javascript" src="../materials/js/function.js"></script> -->
   
</head>
<body>
  <div class="sidebar">
    <div class="logo-dtls">
      <i class='bx bxl-xing'></i>
      <span class="logo">XingX</span>
    </div>

    <ul class="side-nav">
    <li>
    <div class="profile-c">
      <div class="profile-w">
        <img src="../materials/media/logos/test.jpg" alt="">
      </div>

      <div class="name">
        <div class="profile_n">BiroCokoco Duenviake</div>
        <div class="job_n">System Designer</div>
      </div>
      <i class='bx bx-log-out' ></i>
    </div>
  </li>
</ul>
  </div>
</body>
</html>

1 Answers

If you want the details fixed at the bottom I am not sure why you would add them to the sidebar list.

Simply split your side bar into 3 sections head/content/foot e.g (logo/nav/profile)

Then use flex to fix the heights of the head and foot and allow the content to fill the remaining space.

Using flex:column and flex:0 0 60px to fix the heights of head and foot.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Poppins', sans-serif;
}

.sidebar {
  position: fixed;
  top: 0;
  height: 0;
  height: 100%;
  width: 260px;
  background: blue;
  display:flex;
  flex-direction:column;
}

.sidebar .logo-dtls {
  width: 100%;
  display: flex;
  align-items: center;
  flex:0 0 60px;;
}

.sidebar .logo-dtls i {
  font-size: 30px;
  color: #fff;
  height: 50px;
  min-width: 78px;
  text-align: center;
  line-height: 50px;
}

.sidebar .logo-dtls .logo {
  font-size: 22px;
  color: #fff;
  font-weight: 600;
}


/* NAV */

.sidebar .side-nav {
  /* background: red; */
  flex:1;
  padding-top: 30px;
}

.sidebar .side-nav li {
  list-style: none;
  transition: 0.4s ease all;
}

.sidebar .side-nav li i {
  height: 50px;
  min-width: 78px;
  text-align: center;
  line-height: 50px;
  color: #fff;
  font-size: 20px;
}


/* PROFILE CSS */

.sidebar .profile-c {
  display: flex;
  flex:0 0 60px;
  align-items: center;
  justify-content: space-between;
  background: black;
}

.sidebar .profile-c .profile-c {
  display: flex;
  align-items: center;
}

.sidebar .profile-c img {
  height: 52px;
  width: 52px;
  object-fit: cover;
  border-radius: 16px;
  margin: 0 14px 0 12px;
  background: red;
  padding: 10px
}

.sidebar .profile-c .profile_n,
.sidebar .profile-c .job_n {
  color: #fff;
  font-size: 18px;
  font-weight: 500;
}

.sidebar .profile-c .job_n {
  font-size: 12px;
}
<div class="sidebar">

  <div class="logo-dtls">
    <i class='bx bxl-xing'></i>
    <span class="logo">XingX</span>
  </div>

  <ul class="side-nav">
    <li>

    </li>
  </ul>
  
  <div class="profile-c">
    <div class="profile-w">
      <img src="../materials/media/logos/test.jpg" alt="">
    </div>
    <div class="name">
      <div class="profile_n">BiroCokoco Duenviake</div>
      <div class="job_n">System Designer</div>
    </div>
    <i class='bx bx-log-out'></i>
  </div>

</div>

Related