Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
How to Create a Slider using HTML and CSS?
Next article icon

How to create a revealing sidebar using HTML CSS and JavaScript?

Last Updated : 19 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

A revealing sidebar is a hidden UI element that becomes visible upon user interaction, such as clicking or swiping, providing navigation links. The content of the page will rotate and the navigation bar will reveal itself when the menu button is clicked.

Approach

  • Create an HTML file with headings and a navigation bar, link the CSS file for styling, and include icons for opening and closing the navigation bar. Add <script> tags for index.js and icon usage.
  • Reset browser default styles using CSS, apply classes and IDs for styling and layout, and use :hover selectors for interactive effects. Implement animations for smooth transitions and ensure responsive design for various devices.
  • Create index.js, add event listeners to detect and handle mouse click events to manage the navigation bar, ensuring an interactive user experience.

Example: This example shows the implementation of the above-explained approach.

HTML
<!-- Filnename: index.html --> <!DOCTYPE html> <html>  <head>     <link rel="stylesheet" href="style.css"> </head>  <body>     <div class="main_box show-nav">         <div class="circle-container">             <div class="circle">                 <button class="open">                     <i class="fas fa-bars"></i>                 </button>                 <button class="close">                     <i class="fas fa-times"></i>                 </button>             </div>         </div>         <div class="content">             <h1 style="color: green;">                 GeeksforGeeks             </h1>             <small>Hello Geeks</small>             <p>                 GeeksforGeeks is a good platform to                 learn programming. It is an educational                 website. Prepare for the Recruitment drive                 of product based companies like Microsoft,                 Amazon, Adobe etc with a free                 online placement preparation course. The                 course focuses on various MCQ's and Coding                 question likely to be asked in the interviews                 and make your upcoming placement season                 efficient and successful.             </p>              <p>                 Also, any geeks can help other geeks by                 writing articles on the GeeksforGeeks,                 publishing articles follow few steps                 that are Articles that need little                 modification or improvement from reviewers                 are published first. To quickly get your                 articles reviewed, please refer existing                 articles, their formatting style, coding                 style, and try to make you are close to                 them. In case you are a beginner, you                 may refer Guidelines to write an Article.             </p>           </div>     </div>     <nav>         <ul class="nav-links">             <li>home</li>             <li>about</li>             <li>contact</li>         </ul>     </nav>     <script src="https://kit.fontawesome.com/704ff50790.js"         crossorigin="anonymous"></script>     <script src="index.js"></script> </body>  </html> 
CSS
/*Filename: style.css File  */ * {     box-sizing: border-box; }  body {     overflow-x: hidden;     margin: 0;     background: #000;     color: #fff; }  .main_box {     background-color: #fafafa;     color: #000;     transform-origin: top left;     transition: transform 0.5 linear;     width: 100vw;     min-height: 100vh;     padding: 3em; }  .main_box.show-nav {     transform: rotate(-20deg); }  .circle-container {     position: fixed;     top: -6em;     left: -6em; }  .circle {     background-color: #ff7979;     height: 12em;     width: 12em;     border-radius: 50%;     position: relative;     transition: transform 0.5s linear;     cursor: pointer; }  .circle button {     position: absolute;     top: 50%;     left: 50%;     height: 6em;     background: transparent;     border: 0;     color: #fff;     cursor: pointer; }  .circle button:focus {     outline: none; }  .circle button.open {     left: 60%; }  .circle button.close {     top: 60%;     transform: rotate(90deg);     transform-origin: top left; }  .main_box.show-nav .circle {     transform: rotate(-70deg); }  nav {     position: fixed;     left: 0;     bottom: 2.5em;     z-index: 5; }  nav ul {     list-style: none;     padding-left: 2em; }  nav ul li {     text-transform: uppercase;     color: rgb(243, 243, 243);     margin: 2.5em 0;     transform: translateX(-100%);     transition: transform 0.4 ease-in; }  nav ul li+li {     margin-left: 1em;     transform: translateX(-150%); }  nav ul li+li+li {     margin-left: 2em;     transform: translateX(-200%); }  .main_box.show-nav+nav li {     transform: translateX(0);     transition-delay: 0.3s; }  .nav-links {     cursor: pointer; } 
JavaScript
// Filename: index.js  document.addEventListener('DOMContentLoaded', (event) => {     const mainBox = document.querySelector('.main_box');     const circle = document.querySelector('.circle');     const openBtn = document.querySelector('.open');     const closeBtn = document.querySelector('.close');     const navLinks = document.querySelectorAll('nav ul li');      openBtn.addEventListener('click', () => {         mainBox.classList.add('show-nav');         navLinks.forEach((link, index) => {             link.style.transitionDelay = `${index * 0.1}s`;             link.style.transform = 'translateX(0)';         });     });      closeBtn.addEventListener('click', () => {         mainBox.classList.remove('show-nav');         navLinks.forEach((link) => {             link.style.transitionDelay = '0s';             link.style.transform = '';         });     }); }); 

Output:



Next Article
How to Create a Slider using HTML and CSS?

R

rahulmahajann
Improve
Article Tags :
  • CSS
  • JavaScript
  • Web Technologies
  • CSS-Properties
  • HTML-Tags
  • javascript-basics

Similar Reads

  • How to create a Landing page using HTML CSS and JavaScript ?
    A landing page, also referred to as a lead capture page, static page, or destination page, serves a specific purpose and typically appears as a result of online advertising or search engine optimization efforts. Unlike a homepage, a landing page is stripped of distractions and focuses on capturing v
    7 min read
  • How to create a Snackbar using HTML, CSS & JavaScript?
    Snackbar or toast notifications are brief messages that pop up on a webpage to convey information or feedback to users. They are versatile tools for signaling different states, like success, error, or invalid input, and can appear at various positions on the screen. Approach:First, create a basic HT
    3 min read
  • How to Create a Modal Box using HTML CSS and JavaScript?
    We will learn how to create a modal dialog box using HTML, CSS, and JavaScript. A modal is a pop-up dialog that appears on top of the main content and requires the user to interact with it before returning to the main screen. Approach to Create Modal BoxHTML Structure:Create a button that opens the
    2 min read
  • How to Create a Slider using HTML and CSS?
    A slider (also called a slideshow) is a sequence of content frames that users can navigate through. Creating a slider using just HTML and CSS is efficient because it doesn't require JavaScript, making it lightweight and fast. The slider can contain images, text, or any other content you want to show
    3 min read
  • How to Create a Portfolio Website using HTML CSS and JavaScript ?
    A portfolio website is a website that represents you online on the web pages. It contains different sections like Introduction to Yourself, About You, Your Services, Your Contact Details, and Your Portfolio. We are going to build all of the sections with an interactive and attractive web design that
    15+ min read
  • How to create a Popup Form using HTML CSS and JavaScript ?
    To create a popup form using JavaScript, you can design a hidden overlay that becomes visible when triggered. We will use HTML for form elements, CSS for styling, and JavaScript to toggle the visibility of the overlay. This allows for a user-friendly and interactive way to display forms on your webp
    3 min read
  • How to create Popup Box using HTML CSS and JavaScript?
    Creating a popup box with HTML, CSS, and JavaScript improves user interaction on a website. A responsive popup appears when a button is clicked, featuring an HTML structure, CSS for styling, and JavaScript functions to manage visibility. ApproachCreate the Popup structure using HTML tags, Some tags
    3 min read
  • Create a Hoverable Side Navigation with HTML, CSS and JavaScript
    To create hoverable side navigation with icon on any website there is a need for two things HTML and CSS. If you want to attach the icons on the navigation bar then you need a font-awesome CDN link. These features make the website looks cool than a normal website where the nav-bar is old-school desi
    4 min read
  • How to Create Responsive Sidebar using HTML & CSS ?
    Creating a responsive sidebar using HTML and CSS means designing a navigation menu that adapts seamlessly to different screen sizes. It provides a user-friendly experience on both desktop and mobile devices, adjusting its layout for better readability and easy access to content. ApproachBasic Struct
    2 min read
  • Create a Responsive Admin Dashboard using HTML CSS and JavaScript
    An Admin Panel typically has several sections that enable the administrator to manage and control various activities on a website. The layout usually consists of a header and a sidebarnavigation bar, which allows the admin to easily navigate between the various sections of the panel. In the header,
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
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
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences