sidenav overlay on top of sticky navbar, problem with the height of the sidenav overlay












2















I have this problem with the height of the sidenav overlay, I know that its messing with the javascript of the sticky navbar, but I have no idea how to make the height of the sidenav to be at its 100%. Any help would greatly appreciated!



enter image description here



Here is the code:



<html>     
<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>
body {
margin: 0;
font-size: 28px;
font-family: Arial, Helvetica, sans-serif;
}


.header {
background-color: #f1f1f1;
padding: 30px;
text-align: center;
}

#navbar {
overflow: hidden;
background-color: #333;
}

#navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 9px 16px;
text-decoration: none;
font-size: 17px;
}

#navbar a:hover {
background-color: #ddd;
color: black;
}

#navbar a.active {
background-color: #4CAF50;
color: white;
}

.content {
padding: 16px;
}

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

.sticky + .content {
padding-top: 60px;
}
</style>
</head>
<body>

<div class="header">
<h2>Scroll Down</h2>
<p>Scroll down to see the sticky effect.</p>
</div>

<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<div class="w3-sidebar w3-bar-block w3-animate-left" style="display:none;z-index:999;height:100%" id="mySidebar">
<button class="w3-bar-item w3-button w3-large" onclick="w3_close()"> Close &times;</button>
<a class="w3-bar-item w3-button" href="#">Link 1</a>
<a class="w3-bar-item w3-button" href="#">Link 2</a>
<a class="w3-bar-item w3-button" href="#">Link 3</a>
</div>
<div class="w3-overlay w3-animate-opacity" onclick="w3_close()" style="cursor:pointer" id="myOverlay"></div>
<script>
function w3_open() {
document.getElementById("mySidebar").style.display = "block";
document.getElementById("myOverlay").style.display = "block";
}

function w3_close() {
document.getElementById("mySidebar").style.display = "none";
document.getElementById("myOverlay").style.display = "none";
}
</script>
<div id="navbar">
<span class="w3-button w3-white w3-xlarge" onclick="w3_open()">☰</span>

</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>

</div>

<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>


I just need the sidenav to displayed at its 100% height even if it is inside the sticky navbar. Thanks in advance!










share|improve this question



























    2















    I have this problem with the height of the sidenav overlay, I know that its messing with the javascript of the sticky navbar, but I have no idea how to make the height of the sidenav to be at its 100%. Any help would greatly appreciated!



    enter image description here



    Here is the code:



    <html>     
    <head>

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <style>
    body {
    margin: 0;
    font-size: 28px;
    font-family: Arial, Helvetica, sans-serif;
    }


    .header {
    background-color: #f1f1f1;
    padding: 30px;
    text-align: center;
    }

    #navbar {
    overflow: hidden;
    background-color: #333;
    }

    #navbar a {
    float: left;
    display: block;
    color: #f2f2f2;
    text-align: center;
    padding: 9px 16px;
    text-decoration: none;
    font-size: 17px;
    }

    #navbar a:hover {
    background-color: #ddd;
    color: black;
    }

    #navbar a.active {
    background-color: #4CAF50;
    color: white;
    }

    .content {
    padding: 16px;
    }

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

    .sticky + .content {
    padding-top: 60px;
    }
    </style>
    </head>
    <body>

    <div class="header">
    <h2>Scroll Down</h2>
    <p>Scroll down to see the sticky effect.</p>
    </div>

    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <div class="w3-sidebar w3-bar-block w3-animate-left" style="display:none;z-index:999;height:100%" id="mySidebar">
    <button class="w3-bar-item w3-button w3-large" onclick="w3_close()"> Close &times;</button>
    <a class="w3-bar-item w3-button" href="#">Link 1</a>
    <a class="w3-bar-item w3-button" href="#">Link 2</a>
    <a class="w3-bar-item w3-button" href="#">Link 3</a>
    </div>
    <div class="w3-overlay w3-animate-opacity" onclick="w3_close()" style="cursor:pointer" id="myOverlay"></div>
    <script>
    function w3_open() {
    document.getElementById("mySidebar").style.display = "block";
    document.getElementById("myOverlay").style.display = "block";
    }

    function w3_close() {
    document.getElementById("mySidebar").style.display = "none";
    document.getElementById("myOverlay").style.display = "none";
    }
    </script>
    <div id="navbar">
    <span class="w3-button w3-white w3-xlarge" onclick="w3_open()">☰</span>

    </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>

    </div>

    <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>


    I just need the sidenav to displayed at its 100% height even if it is inside the sticky navbar. Thanks in advance!










    share|improve this question

























      2












      2








      2








      I have this problem with the height of the sidenav overlay, I know that its messing with the javascript of the sticky navbar, but I have no idea how to make the height of the sidenav to be at its 100%. Any help would greatly appreciated!



      enter image description here



      Here is the code:



      <html>     
      <head>

      <meta name="viewport" content="width=device-width, initial-scale=1">

      <style>
      body {
      margin: 0;
      font-size: 28px;
      font-family: Arial, Helvetica, sans-serif;
      }


      .header {
      background-color: #f1f1f1;
      padding: 30px;
      text-align: center;
      }

      #navbar {
      overflow: hidden;
      background-color: #333;
      }

      #navbar a {
      float: left;
      display: block;
      color: #f2f2f2;
      text-align: center;
      padding: 9px 16px;
      text-decoration: none;
      font-size: 17px;
      }

      #navbar a:hover {
      background-color: #ddd;
      color: black;
      }

      #navbar a.active {
      background-color: #4CAF50;
      color: white;
      }

      .content {
      padding: 16px;
      }

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

      .sticky + .content {
      padding-top: 60px;
      }
      </style>
      </head>
      <body>

      <div class="header">
      <h2>Scroll Down</h2>
      <p>Scroll down to see the sticky effect.</p>
      </div>

      <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
      <div class="w3-sidebar w3-bar-block w3-animate-left" style="display:none;z-index:999;height:100%" id="mySidebar">
      <button class="w3-bar-item w3-button w3-large" onclick="w3_close()"> Close &times;</button>
      <a class="w3-bar-item w3-button" href="#">Link 1</a>
      <a class="w3-bar-item w3-button" href="#">Link 2</a>
      <a class="w3-bar-item w3-button" href="#">Link 3</a>
      </div>
      <div class="w3-overlay w3-animate-opacity" onclick="w3_close()" style="cursor:pointer" id="myOverlay"></div>
      <script>
      function w3_open() {
      document.getElementById("mySidebar").style.display = "block";
      document.getElementById("myOverlay").style.display = "block";
      }

      function w3_close() {
      document.getElementById("mySidebar").style.display = "none";
      document.getElementById("myOverlay").style.display = "none";
      }
      </script>
      <div id="navbar">
      <span class="w3-button w3-white w3-xlarge" onclick="w3_open()">☰</span>

      </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>

      </div>

      <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>


      I just need the sidenav to displayed at its 100% height even if it is inside the sticky navbar. Thanks in advance!










      share|improve this question














      I have this problem with the height of the sidenav overlay, I know that its messing with the javascript of the sticky navbar, but I have no idea how to make the height of the sidenav to be at its 100%. Any help would greatly appreciated!



      enter image description here



      Here is the code:



      <html>     
      <head>

      <meta name="viewport" content="width=device-width, initial-scale=1">

      <style>
      body {
      margin: 0;
      font-size: 28px;
      font-family: Arial, Helvetica, sans-serif;
      }


      .header {
      background-color: #f1f1f1;
      padding: 30px;
      text-align: center;
      }

      #navbar {
      overflow: hidden;
      background-color: #333;
      }

      #navbar a {
      float: left;
      display: block;
      color: #f2f2f2;
      text-align: center;
      padding: 9px 16px;
      text-decoration: none;
      font-size: 17px;
      }

      #navbar a:hover {
      background-color: #ddd;
      color: black;
      }

      #navbar a.active {
      background-color: #4CAF50;
      color: white;
      }

      .content {
      padding: 16px;
      }

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

      .sticky + .content {
      padding-top: 60px;
      }
      </style>
      </head>
      <body>

      <div class="header">
      <h2>Scroll Down</h2>
      <p>Scroll down to see the sticky effect.</p>
      </div>

      <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
      <div class="w3-sidebar w3-bar-block w3-animate-left" style="display:none;z-index:999;height:100%" id="mySidebar">
      <button class="w3-bar-item w3-button w3-large" onclick="w3_close()"> Close &times;</button>
      <a class="w3-bar-item w3-button" href="#">Link 1</a>
      <a class="w3-bar-item w3-button" href="#">Link 2</a>
      <a class="w3-bar-item w3-button" href="#">Link 3</a>
      </div>
      <div class="w3-overlay w3-animate-opacity" onclick="w3_close()" style="cursor:pointer" id="myOverlay"></div>
      <script>
      function w3_open() {
      document.getElementById("mySidebar").style.display = "block";
      document.getElementById("myOverlay").style.display = "block";
      }

      function w3_close() {
      document.getElementById("mySidebar").style.display = "none";
      document.getElementById("myOverlay").style.display = "none";
      }
      </script>
      <div id="navbar">
      <span class="w3-button w3-white w3-xlarge" onclick="w3_open()">☰</span>

      </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>

      </div>

      <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>


      I just need the sidenav to displayed at its 100% height even if it is inside the sticky navbar. Thanks in advance!







      javascript html css sidenav






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 9:29









      midnightcatmidnightcat

      304




      304
























          1 Answer
          1






          active

          oldest

          votes


















          2















          1. Set position: relative for your header.

          2. Set position: absolute; top: 0 for a sidebar.
            It works for me. I hope does for you too.






          share|improve this answer
























          • It worked! Thanks a lot!

            – midnightcat
            Jan 2 at 7:45











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994351%2fsidenav-overlay-on-top-of-sticky-navbar-problem-with-the-height-of-the-sidenav%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2















          1. Set position: relative for your header.

          2. Set position: absolute; top: 0 for a sidebar.
            It works for me. I hope does for you too.






          share|improve this answer
























          • It worked! Thanks a lot!

            – midnightcat
            Jan 2 at 7:45
















          2















          1. Set position: relative for your header.

          2. Set position: absolute; top: 0 for a sidebar.
            It works for me. I hope does for you too.






          share|improve this answer
























          • It worked! Thanks a lot!

            – midnightcat
            Jan 2 at 7:45














          2












          2








          2








          1. Set position: relative for your header.

          2. Set position: absolute; top: 0 for a sidebar.
            It works for me. I hope does for you too.






          share|improve this answer














          1. Set position: relative for your header.

          2. Set position: absolute; top: 0 for a sidebar.
            It works for me. I hope does for you too.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 1 at 9:41









          Mila LysenkoMila Lysenko

          862




          862













          • It worked! Thanks a lot!

            – midnightcat
            Jan 2 at 7:45



















          • It worked! Thanks a lot!

            – midnightcat
            Jan 2 at 7:45

















          It worked! Thanks a lot!

          – midnightcat
          Jan 2 at 7:45





          It worked! Thanks a lot!

          – midnightcat
          Jan 2 at 7:45




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994351%2fsidenav-overlay-on-top-of-sticky-navbar-problem-with-the-height-of-the-sidenav%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith