Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS Sticky Nav, put on bottom originally

bendylicious

New Coder
Hi to all professionals,

I am a beginner and practising a lot at home.
At the moment I try to position a navbar at the bottom of my viewport. The navbar should be scrolled up and stay fixed on the top while the content can be scrolled further.
I began, with a little bit of help of to create a HTML, BOTTSTRAP5 and a CSS Code, but it`s not working.
Has anyone an idea what my problem is?
HTML:
<!DOCTYPE html>
<html lang="de">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Die Webseitengestalterin</title>
  <meta content="websites, webseiten, webseitengestaltung, webdesign, bootstrap, css, scss, UGC, User Generated Content, Internetauftritt" name="description">

  <!-- Favicons --> <!--Nicht auf zu finden-->
  <link href="assets/img/favicon.png" rel="icon">
  <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
 
  <script src="https://kit.fontawesome.com/b45c110477.js" crossorigin="anonymous"></script>
  <!-- Google Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">


  <!-- Vendor CSS Files -->
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
  <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="scss/scss.css" rel="stylesheet">

</head>

<body>
    
  <header>
    <h2>Scroll Down</h2>
      <p>Scroll down to see the sticky effect.</p>
  </header>

      <!-- ======= Navigation ======= -->
    <div id="navbar">
      <div class="navbar navbar-expand-lg sticky">
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav">
            <li class="nav-item">
              <a class="nav-link active" aria-current="page" href="javascript:void(0)">Home</a>
            </li>
            <li class="nav-item">
              <a class="nav-link"  href="javascript:void(0)">Features</a>
            </li>
            <li class="nav-item">
              <a class="nav-link"  href="javascript:void(0)">Pricing</a>
            </li>
            <li class="nav-item">
              <a class="nav-link"  href="javascript:void(0)">Disabled</a>
            </li>
          </ul>
        </div>
      </div>
    </div>

  <div class="content">
    <h3>Sticky Navigation Example</h3>
    <p>The navbar will stick to the top when you reach its scroll position.</p>
    <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
    <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
    <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
    <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
    <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
    <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
    <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
  </div>



  <!-- ======= Footer ======= -->
  <footer>
  </footer><!-- End Footer -->

  <!-- Vendor JS Files -->
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/glightbox/js/glightbox.min.js"></script>
  <script src="assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>
  <script src="assets/vendor/purecounter/purecounter.js"></script>
  <script src="assets/vendor/swiper/swiper-bundle.min.js"></script>

  <!-- Template Main JS File -->
  <script src="assets/js/main.js"></script>
 
  <script>
    window.onscroll = function() {myFunction()};
    
    var navbar = document.getElementById("navbar");
    var sticky = navbar.offsetTop;
    
    function myFunction() {
      if (window.pageYOffset >= sticky) {
        navbar.classList.add("sticky")
      } else {
        navbar.classList.remove("sticky");
      }
    }
    </script>

</body>

</html>

CSS:
@import "bootstrap/bootstrap";

//General

li, ul{
    padding: 0;
    margin: 0;
    overflow: auto;
    list-style: none;
  }
  
  a {
    text-decoration: none;
    color: #ffffff;
  }


  // Navigation
.header {
box-sizing: border-box;
padding: 30px;
}

.navbar {
border: 2px solid yellow;
background-color: #324169;
}

.navbar-nav {
border: 2px solid red;
justify-content: center;
width: 100%; // zieht die Navigation in die Länge
}

#navbar {
border: 2px solid blue;
overflow: hidden;
}

#navbar a {
display:block;
text-decoration: 0;
color: #ffffff;
text-align: center;
padding: 14px 16px;
}

#navbar a:hover {
color: #99c0d5;   
}

#navbar a:active  {
color: #99c0d5;   
}

.sticky {
    position: sticky;
    top: 0;
    width: 100%;
  }

  .sticky + .content {
    padding-top: 60px;
  }

 
.content {
    padding: 16px;
  }
 
I have tried this as well and it worked, could you tell us what you are seeing, what you want and what browser are you using?
 
Since two members are saying it works, it likely is something related to your browser / JS. Another thing it could be is your browser caching previous HTML/JS. Try incognito mode, a hard-refresh, or clearing the cache manually. It's most likely related to that CSS file being cached in my opinion.
 
Back
Top Bottom