How to Create Full Screen Overlay Navigation Bar using HTML CSS and JavaScript ?
Last Updated : 24 Apr, 2020
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
Create a full screen Navigation Bar: In this article, you will learn how to create a full-screen navbar for your website. There are three methods to create a full screen overlay navigation bar which are listed below:
From Left
From top
No animation- Just show
You will be required to create two divs. One for the overlay container and the other for the overlay content container.
Step 1: The first step is to create an HTML file.
html
<divid="myNav"class="overlay"><!-- Button to close the overlay navigation --><ahref="javascript:void(0)"class="closebtn"onclick="closeNav()">×</a><!-- Overlay content --><divclass="overlay-content"><ahref="#">About</a><ahref="#">Services</a><ahref="#">Clients</a><ahref="#">Contact</a></div></div><!-- Use any element to open/show the overlay navigation menu --><spanonclick="openNav()">open</span></div>
Step 2: Add CSS to the file.
css
<style>overlay{height:100%;width:0;position:fixed;]z-index:1;left:0;top:0;background-color:rgb(0,0,0);background-color:rgba(0,0,0,0.9);overflow-x:hidden;transition:0.5s;}].overlay-content{position:relative;top:25%;width:100%;text-align:center;margin-top:30px;}.overlaya{padding:8px;text-decoration:none;font-size:36px;color:#818181;/* Display block instead of inline */display:block;/* Transition effects on hover (color) */transition:0.3s;}.overlaya:hover,.overlaya:focus{color:#f1f1f1;}.overlay.closebtn{position:absolute;top:20px;right:45px;font-size:60px;}@mediascreenand(max-height:450px){.overlaya{font-size:20px}.overlay.closebtn{font-size:40px;top:15px;right:35px;}}</style>
Step 3: In the final step add JavaScript to the files.
javascript
Example 1: This example creating the Full Screen Overlay Navigation Bar from left.
html
<!DOCTYPE html><html><head><metaname="viewport"content="width=device-width, initial-scale=1"><style>.overlay{height:100%;width:0;position:fixed;top:0;left:0;background-color:#1a6e1a;overflow-x:hidden;transition:1.0s;}.overlay-content{position:relative;top:25%;width:100%;text-align:center;}.overlaya{padding:10px;text-decoration:none;font-size:40px;color:white;display:block;transition:0.3s;}.overlaya:hover,.overlaya:focus{color:black;}.overlay.closebtn{position:absolute;top:10px;right:35px;font-size:70px;}</style></head><body><divid="myNav"class="overlay"><ahref="javascript:void(0)"class="closebtn"onclick="closeNav()">×</a><divclass="overlay-content"><ahref="#">About</a><ahref="#">Practice</a><ahref="#">Courses</a><ahref="#">Contact</a></div></div><spanstyle="font-size:35px;cursor:pointer"onclick="openNav()">≡</span><h2>GeeksForGeeks</h2><p>
Click on the nav bar icon
to see full screen overlay:
</p><script>functionopenNav(){document.getElementById("myNav").style.width="100%";}functioncloseNav(){document.getElementById("myNav").style.width="0%";}</script></body></html>
Output:Example 2: This example creating the Full-Screen Overlay Navigation Bar from the top.
html
<!DOCTYPE html><html><head><metaname="viewport"content="width=device-width, initial-scale=1"><style>.overlay{height:0%;width:100%;position:fixed;top:0;left:0;background-color:#1a6e1a;overflow-y:hidden;transition:1.0s;}.overlay-content{position:relative;top:25%;width:100%;text-align:center;}.overlaya{padding:10px;text-decoration:none;font-size:40px;color:white;display:block;transition:0.3s;}.overlaya:hover,.overlaya:focus{color:black;}.overlay.closebtn{position:absolute;top:10px;right:35px;font-size:70px;}</style></head><body><divid="myNav"class="overlay"><ahref="javascript:void(0)"class="closebtn"onclick="closeNav()">×</a><divclass="overlay-content"><ahref="#">About</a><ahref="#">Practice</a><ahref="#">Courses</a><ahref="#">Contact</a></div></div><spanstyle="font-size:35px;cursor:pointer"onclick="openNav()">≡</span><h2>GeeksForGeeks</h2><p>
Click on the nav bar icon
to see full screen overlay:
</p><script>functionopenNav(){document.getElementById("myNav").style.height="100%";}functioncloseNav(){document.getElementById("myNav").style.height="0%";}</script></body></html>
Output:Example 3: This example creating the Full-Screen Overlay Navigation Bar without animation.
html
<!DOCTYPE html><html><head><metaname="viewport"content="width=device-width, initial-scale=1"><style>.overlay{height:100%;width:100%;display:none;position:fixed;top:0;left:0;background-color:#1a6e1a;}.overlay-content{position:relative;top:25%;width:100%;text-align:center;}.overlaya{padding:10px;text-decoration:none;font-size:40px;color:white;display:block;transition:0.3s;}.overlaya:hover,.overlaya:focus{color:black;}.overlay.closebtn{position:absolute;top:10px;right:35px;font-size:70px;}</style></head><body><divid="myNav"class="overlay"><ahref="javascript:void(0)"class="closebtn"onclick="closeNav()">×</a><divclass="overlay-content"><ahref="#">About</a><ahref="#">Practice</a><ahref="#">Courses</a><ahref="#">Contact</a></div></div><spanstyle="font-size:35px;cursor:pointer"onclick="openNav()">≡</span><h2>GeeksForGeeks</h2><p>
Click on the nav bar icon to
see full screen overlay:
</p><script>functionopenNav(){document.getElementById("myNav").style.display="block";}functioncloseNav(){document.getElementById("myNav").style.display="none";}</script></body></html>
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.