skip to Main Content

I’m trying to make a navigation bar at the bottom of my webpage using CSS, but cannot figure out how to make it stay at the bottom.

HTML:

<div id="navbar" style="position: ??????; left: 0; right: 0; bottom: 0; height: 50px; background-color: #333; padding: 0; font-weight: bold; color: #c5cad0;">

</div>

When I set position as ‘absolute’, the bar stayed in the middle of the page when I scrolled down.

When I set position as ‘fixed’, the bar showed up on the bottom of the screen before I scrolled down.

When I used ‘static, relative, or sticky’, the bar was below the content, but not full width and not all the way at the bottom.

I am trying to get the bar at the bottom of the page, below all of the content (like Stack Overflow does).

2

Answers


  1. @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500&display=swap');
    
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: 'Poppins', sans-serif;
    }
    
    .navbar {
      position: fixed;  /*Navbar will not move from its position if you want when you scroll it stuck at top then just replace position: fixed with sticky*/
      bottom: 0;
      width: 100vw;
      height: 70px;
      background-color: #11101b;
      color: #fefefe;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    
    .left-navbar,
    .hamburger {
      width: 75%;
      height: 100%;
      display: flex;
    }
    
    .heading {
      width: 20%;
      font-size: 1.8em;
      padding: 0px 20px;
      margin-bottom: 5px;
      cursor: pointer;
    }
    
    ul {
      height: 100%;
      display: flex;
      align-items: center;
      list-style-type: none;
    }
    
    li {
      font-size: 1.1em;
      cursor: pointer;
      padding: 20px;
    }
    
    ul:nth-child(5) {
      width: 100vw;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .searchBox {
      width: 30vw;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: space-evenly;
      margin-left: 10vw;
    }
    
    .searchBox input[type="text"] {
      width: 70%;
      border: none;
      outline: none;
      border-radius: 4px;
      padding: 10px 5px;
      margin-right: 5px;
    }
    
    .searchBox input[type="submit"] {
      min-width: 100px;
      padding: 8px 12px;
      border-radius: 4px;
      margin-right: 5px;
    }
    
    .hamburger {
      display: none;
    }
    
    .hamburger-icon {
      display: none;
      cursor: pointer;
    }
    
    .bar1,
    .bar2,
    .bar3 {
      width: 30px;
      height: 3px;
      background-color: white;
      margin: 6px 0;
    }
    
    .change .bar1 {
      transform: translate(0, 8px) rotate(-45deg);
      -webkit-transform: translate(0, 8px) rotate(-45deg);
      -moz-transform: translate(0, 8px) rotate(-45deg);
      -ms-transform: translate(0, 8px) rotate(-45deg);
      -o-transform: translate(0, 8px) rotate(-45deg);
    }
    
    .change .bar2 {
      opacity: 0;
    }
    
    .change .bar3 {
      transform: translate(0, -11px) rotate(45deg);
    }
    
    @media only screen and (max-width: 1340px) {
      .searchBox {
        margin-left: 5vw;
      }
    }
    @media only screen and (max-width: 1160px) {
      .searchBox {
        margin-left: 4vw;
      }
      .left-navbar {
        width: 90%;
      }
    }
    
    @media only screen and (max-width: 1060px) {
      .searchBox {
        margin-left: 2vw;
      }
      .searchBox input[type="submit"] {
        min-width: 60px;
      }
    
      li,
      li:hover {
        padding: 13px;
      }
    }
    
    @media only screen and (max-width: 800px) {
      .left-navbar {
        display: none;
        transition: 0.5s;
      }
      .hamburger {
        display: flex;
        justify-content: end;
        align-items: center;
        margin-right: 20px;
      }
    
      .hamburger-icon {
        display: inline-block;
      }
    
      .left-navbar {
        flex-direction: column;
        position: absolute;
        bottom: 300px;
        width: 100vw;
      }
    
      .left-navbar.active {
        display: flex;
      }
    
      .left-navbar li {
        width: 100vw;
        background-color: #11101b;
        color: #fefefe;
        text-align: center;
      }
      .left-navbar ul {
        flex-direction: column;
      }
    
      .searchBox {
        width: 100vw;
        display: flex;
        justify-content: center;
        margin-left: 0px;
        margin-right: 0px;
      }
    }
    <!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>Navbar</title>
        <link rel="stylesheet" href="style.css" />
      </head>
      <body>
        <nav>
          <div class="navbar">
            <h2 class="heading">Navbar</h2>
            <div class="hamburger">
              <div class="hamburger-icon" onclick="toggleNavbar(this)">
                <div class="bar1"></div>
                <div class="bar2"></div>
                <div class="bar3"></div>
              </div>
            </div>
            <div class="left-navbar">
              <ul>
                <li>Home</li>
                <li>Services</li>
                <li>About</li>
                <li>Contact us</li>
                <li>
                <div class="searchBox">
                    <input type="text" name="search" id="search-input" />
                    <input type="submit" value="Search" />
                </div>
                </li>
              </ul>
            </div>
          </div>
        </nav>
    
        <script>
          let isHamburgerClicked = false;
          function toggleNavbar(x) {
            x.classList.toggle("change");
            document.querySelector('.left-navbar').classList.toggle('active');
            isHamburgerClicked = !isHamburgerClicked;
          }
    
        </script>
      </body>
    </html>
    Login or Signup to reply.
  2. Looks like you need z-index and width with position

    try this:

    <div id="navbar" style="position: fixed; right: 0; bottom: 0; height: 50px; background-color: #333; padding: 0; font-weight: bold; color: #c5cad0; z-index: 9999; width: 100%;">
       Here I am!
    </div>

    This should resolve your issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search