Home > Blockchain >  Getting a li-element in sidebar correctly stick at the bottom
Getting a li-element in sidebar correctly stick at the bottom

Time:01-18

I'm adopting the dashboard example from https://getbootstrap.com/docs/5.0/examples/dashboard/ for a custom page. I'm now trying to add an li element (or a second ul) that sticks at the bottom of the sidebar. The li shall contain a button which streches over the complete width of the sidebar. I already tried adding fixed-bottom which worked for placing the li element at the bottom but the button (width: 100%) is now stretching over the complete page. So I'm not sure if fixed-buttom is the right way to go for.

<div >   
    <nav id="sidebarMenu" >
        <div >
            <ul >
                <li >1</li>
                <li >2</li>
                <li >3</li>
            </ul>
            <!-- this shall be sticky at the bottom of the sidebar -->
            <ul >
            <li>
                <div  style="width:100%">
                <button type="button"  data-bs-toggle="dropdown" aria-expanded="false">my button</button>
                <ul >
                    <li >1</li>
                    <li >2</li>
                </ul>
                </div>
            </li>
            </ul>
        </div>
    </nav>

    <main >
        <!-- CONTENT -->
    </main>
</div>

CodePudding user response:

Here you go...

Basically, make two div elements (upper_part and lower_part). Add the following CSS:

#upper_part {
    height: 80%; /* 80%   20% = 100% */
}

#lower_part {
    height: 20%; /* 80%   20% = 100% */
    padding: 3%;
    padding-bottom: 10%;
}

.my_button {
    width: 100%; /* Make the button full-width. */
}

See the snippet below.

body {
  font-size: .875rem;
}

.feather {
  width: 16px;
  height: 16px;
  vertical-align: text-bottom;
}


/*
   * Sidebar
   */

.sidebar {
  position: fixed;
  top: 0;
  /* rtl:raw:
    right: 0;
    */
  bottom: 0;
  /* rtl:remove */
  left: 0;
  z-index: 100;
  /* Behind the navbar */
  padding: 48px 0 0;
  /* Height of navbar */
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}

@media (max-width: 767.98px) {
  .sidebar {
    top: 5rem;
  }
}

.sidebar-sticky {
  position: relative;
  top: 0;
  height: calc(100vh - 48px);
  padding-top: .5rem;
  overflow-x: hidden;
  overflow-y: auto;
  /* Scrollable contents if viewport is shorter than content. */
}

.sidebar .nav-link {
  font-weight: 500;
  color: #333;
}

.sidebar .nav-link .feather {
  margin-right: 4px;
  color: #727272;
}

.sidebar .nav-link.active {
  color: #2470dc;
}

.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
  color: inherit;
}

.sidebar-heading {
  font-size: .75rem;
  text-transform: uppercase;
}


/*
   * Navbar
   */

.navbar-brand {
  padding-top: .75rem;
  padding-bottom: .75rem;
  font-size: 1rem;
  background-color: rgba(0, 0, 0, .25);
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}

.navbar .navbar-toggler {
  top: .25rem;
  right: 1rem;
}

.navbar .form-control {
  padding: .75rem 1rem;
  border-width: 0;
  border-radius: 0;
}

.form-control-dark {
  color: #fff;
  background-color: rgba(255, 255, 255, .1);
  border-color: rgba(255, 255, 255, .1);
}

.form-control-dark:focus {
  border-color: transparent;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}

#upper_part {
  height: 80%;
}

#lower_part {
  height: 20%;
  padding: 3%;
  padding-bottom: 10%;
}

.my_button {
  width: 100%;
}
<!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='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css' integrity='sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU' crossorigin='anonymous'>
  <script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js' integrity='sha384-skAcpIdS7UcVUC05LJ9Dxay8AXcDYfBJqt1CJ85S/CFujBsIzCIv l9liuYLaMQ/' crossorigin='anonymous'></script>

</head>

<body>

  <header >
    <a  href="#">Company name</a>
    <button  type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation">
          <span ></span>
        </button>
    <input  type="text" placeholder="Search" aria-label="Search">
    <div >
      <div >
        <a  href="#">Sign out</a>
      </div>
    </div>
  </header>

  <div >
    <div >
      <nav id="sidebarMenu" >
        <div  id="upper_part">
          <ul >
            <li >
              <a  aria-current="page" href="#">
                <span data-feather="home"></span> Dashboard
              </a>
            </li>
            <li >
              <a  href="#">
                <span data-feather="file"></span> Orders
              </a>
            </li>
            <li >
              <a  href="#">
                <span data-feather="shopping-cart"></span> Products
              </a>
            </li>
            <li >
              <a  href="#">
                <span data-feather="users"></span> Customers
              </a>
            </li>
            <li >
              <a  href="#">
                <span data-feather="bar-chart-2"></span> Reports
              </a>
            </li>
            <li >
              <a  href="#">
                <span data-feather="layers"></span> Integrations
              </a>
            </li>
          </ul>

          <h6 >
            <span>Saved reports</span>
            <a  href="#" aria-label="Add a new report">
              <span data-feather="plus-circle"></span>
            </a>
          </h6>
          <ul >
            <li >
              <a  href="#">
                <span data-feather="file-text"></span> Current month
              </a>
            </li>
            <li >
              <a  href="#">
                <span data-feather="file-text"></span> Last quarter
              </a>
            </li>
            <li >
              <a  href="#">
                <span data-feather="file-text"></span> Social engagement
              </a>
            </li>
            <li >
              <a  href="#">
                <span data-feather="file-text"></span> Year-end sale
              </a>
            </li>
          </ul>

        </div>
        <div  id="lower_part">
          <button type="button" >Yay, it works.</button>
        </div>

      </nav>

      <main >
        <div >
          <h1 >Dashboard</h1>
          <div >
            <div >
              <button type="button" >Share</button>
              <button type="button" >Export</button>
            </div>
            <button type="button" >
                  <span data-feather="calendar"></span>
                  This week
                </button>
          </div>
        </div>

        <canvas  id="myChart" width="900" height="380"></canvas>

        <h2>Section title</h2>
        <div >
          <table >
            <thead>
              <tr>
                <th scope="col">#</th>
                <th scope="col">Header</th>
                <th scope="col">Header</th>
                <th scope="col">Header</th>
                <th scope="col">Header</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>1,001</td>
                <td>random</td>
                <td>data</td>
                <td>placeholder</td>
                <td>text</td>
              </tr>
              <tr>
                <td>1,002</td>
                <td>placeholder</td>
                <td>irrelevant</td>
                <td>visual</td>
                <td>layout</td>
              </tr>
              <tr>
                <td>1,003</td>
                <td>data</td>
                <td>rich</td>
                <td>dashboard</td>
                <td>tabular</td>
              </tr>
              <tr>
                <td>1,003</td>
                <td>information</td>
                <td>placeholder</td>
                <td>illustrative</td>
                <td>data</td>
              </tr>
              <tr>
                <td>1,004</td>
                <td>text</td>
                <td>random</td>
                <td>layout</td>
                <td>dashboard</td>
              </tr>
              <tr>
                <td>1,005</td>
                <td>dashboard</td>
                <td>irrelevant</td>
                <td>text</td>
                <td>placeholder</td>
              </tr>
              <tr>
                <td>1,006</td>
                <td>dashboard</td>
                <td>illustrative</td>
                <td>rich</td>
                <td>data</td>
              </tr>
              <tr>
                <td>1,007</td>
                <td>placeholder</td>
                <td>tabular</td>
                <td>information</td>
                <td>irrelevant</td>
              </tr>
              <tr>
                <td>1,008</td>
                <td>random</td>
                <td>data</td>
                <td>placeholder</td>
                <td>text</td>
              </tr>
              <tr>
                <td>1,009</td>
                <td>placeholder</td>
                <td>irrelevant</td>
                <td>visual</td>
                <td>layout</td>
              </tr>
              <tr>
                <td>1,010</td>
                <td>data</td>
                <td>rich</td>
                <td>dashboard</td>
                <td>tabular</td>
              </tr>
              <tr>
                <td>1,011</td>
                <td>information</td>
                <td>placeholder</td>
                <td>illustrative</td>
                <td>data</td>
              </tr>
              <tr>
                <td>1,012</td>
                <td>text</td>
                <td>placeholder</td>
                <td>layout</td>
                <td>dashboard</td>
              </tr>
              <tr>
                <td>1,013</td>
                <td>dashboard</td>
                <td>irrelevant</td>
                <td>text</td>
                <td>visual</td>
              </tr>
              <tr>
                <td>1,014</td>
                <td>dashboard</td>
                <td>illustrative</td>
                <td>rich</td>
                <td>data</td>
              </tr>
              <tr>
                <td>1,015</td>
                <td>random</td>
                <td>tabular</td>
                <td>information</td>
                <td>text</td>
              </tr>
            </tbody>
          </table>
        </div>
      </main>
    </div>
  </div>


  <script src="../assets/dist/js/bootstrap.bundle.min.js"></script>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
  <script src="dashboard.js"></script>


</body>

</html>

  •  Tags:  
  • Related