Best Website-BuildersBest Website-Builders
    What's Hot

    Clearview AI used nearly 1m times by US police, it tells the BBC

    March 27, 2023

    The Papers: Fight for union and 'crackdown on party houses'

    March 27, 2023

    Unboxing Is So 2012. The Internet Wants Packing Videos

    March 27, 2023
    Facebook Twitter Instagram
    Facebook Twitter Instagram
    Best Website-BuildersBest Website-Builders
    • Home
    • CSS

      The 2023 Nagaland State Budget presents state matching shares for the CSS for the first time.

      March 27, 2023

      XHTML: Should Doctype, Meta and Link be closed as single tags? – HTML and CSS – SitePoint Forum

      March 27, 2023

      Annual Development Outlay for 2023-24 fixed at Rs 82,000 lakh | MorungExpress

      March 27, 2023

      Web Scraping with Python and Selenium | Daniel Ellis Research | | March 2023

      March 27, 2023

      Gunboat Association, Partners Host Environmental Education Day on April 1 — News News

      March 27, 2023
    • Joomla

      An In-Depth Study of the Market Status, Trends and Top Players of the Open Source Content Management Systems Market

      March 27, 2023

      Save Thousands On Web Hosting With iBrave, Now Only $86

      March 23, 2023

      In Vitro Transcription Services Market Analysis, Research Study with Shanghai Zhishuo Biotechnology Co., Yunzhou Biotechnology Co.

      March 23, 2023

      Current state of UK content management systems

      March 23, 2023

      Reseller Hosting Business: Important Q&A

      March 21, 2023
    • PHP

      Gov. Bill Lee Offers Prayers to Nashville Victims After Opposing Gun Control

      March 27, 2023

      Seaweed ‘blobs’ approaching Florida: health risks

      March 27, 2023

      Ashbey Beasley asked reporters if they were tired of covering mass shootings after the Nashville school shooting

      March 27, 2023

      We spoke to the man behind the Pope’s viral AI image

      March 27, 2023

      TikTok’s WAGs want to show what their lives are really like

      March 27, 2023
    • UX

      Introducing the new Microsoft Teams app with a new user experience

      March 27, 2023

      Experience Optimization Product Acronym Translation

      March 27, 2023

      Microsoft rebuilds Teams from the ground up, promising 2x faster performance

      March 27, 2023

      Flow Fournier on Designing a Better Future with AI

      March 27, 2023

      Uptime.com offers synthetic transaction monitoring to track performance, user experience and prevent revenue loss

      March 27, 2023
    • Web Builders
      1. Web Design
      2. View All

      What Comes First in Website Development — Design or Copy?

      February 2, 2023

      Modern Campus Honors Best Higher Education Websites of 2022

      February 2, 2023

      Premier SEO Consultant in Las Vegas, Nevada with Unparalleled Customer Service

      February 2, 2023

      Can Religious Freedom Be Saved? This group is racing the clock to teach America’s first freedom

      February 2, 2023

      How i Create New Google Account

      February 7, 2023

      CWT powers tools for meeting and event planners

      January 31, 2023

      Best Website Builder – Website Builders

      January 24, 2023

      Is There A Market For Rap-Themed Slot Games? – Rap Review

      January 19, 2023
    • WordPress

      AMD Reveals New Details For Next-Gen FSR 3, Could Change The Game

      March 27, 2023

      Apple brings AI Chat to more places on MacBook

      March 27, 2023

      Apple Music Classical hits the first note – here’s what it looks like

      March 27, 2023

      LG doesn’t make phones, but Android 13 update arrives before Motorola

      March 27, 2023

      Motorola’s upcoming flagship looks set to go global, impressed by spec leak

      March 27, 2023
    • Realtoz
      • Our Other Sites
    • More News
    Best Website-BuildersBest Website-Builders
    Home » Add a hamburger toggle to your website – HTML & CSS – SitePoint Forums
    CSS

    Add a hamburger toggle to your website – HTML & CSS – SitePoint Forums

    websitebuildersnowBy websitebuildersnowMay 21, 2022No Comments9 Mins Read
    Facebook Twitter LinkedIn Telegram Pinterest Tumblr Reddit WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Email



    apache


    May 21, 2022 at 1:49 PM


    #1

    Hello everyone.

    I am currently learning how to make a website. I built a website using HTML CSS Javascript. I’m currently trying to learn how to collapse a website into vertical navigation as shown on this website.I’m attaching a link here so you can get an idea: https://mdbootstrap.com/snippets/jquery/mdbootstrap/911242#html – tab view



    apache


    May 21, 2022 at 1:55 PM


    #2

    [<!DOCTYPE html>
    <html lang="en">
      <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <link rel="stylesheet" href="https://news.google.com/__i/rss/rd/articles/styles.css" />
        <script src="script.js" defer></script>
      </head>
      <body>
        <header>
            <img class="logo" src="images/new logo.png" alt="logo">
            <div class="navbar__toggle" id="mobile-menu">
              <span class="bar"></span>
              <span class="bar"></span>
              <span class="bar"></span>
            </div>
            <nav class="nav">
            <div class="dropdown" data-dropdown>
            <button class="link" data-dropdown-button>Information</button>
            <div class="dropdown-menu information-grid">
              <div>
                <div class="dropdown-heading">Free Tutorials</div>
                <div class="dropdown-links">
                  <a href="#" class="link">All</a>
                  <a href="#" class="link">Latest</a>
                  <a href="#" class="link">Popular</a>
                </div>
              </div>
              <div>
                <div class="dropdown-heading">Courses</div>
                <div class="dropdown-links">
                  <a href="#" class="link">Javascript</a>
                  <a href="#" class="link">CSS</a>
                  <a href="#" class="link">React</a>
                </div>
              </div>
              <div>
                <div class="dropdown-heading">Blog</div>
                <div class="dropdown-links">
                  <a href="#" class="link">All</a>
                  <a href="#" class="link">Latest</a>
                  <a href="#" class="link">Popular</a>
                </div>
              </div>
              <div>
                <div class="dropdown-heading">Other</div>
                <div class="dropdown-links">
                  <a href="#" class="link">Twitter</a>
                  <a href="#" class="link">Newsletter</a>
                  <a href="#" class="link">Discord</a>
                </div>
              </div>
            </div>
          </div>
          <a href="#" class="link">Pricing</a>
          <div class="dropdown" data-dropdown> 
          <button class="link" data-dropdown-button>Login</button>
          <div class="dropdown-menu">
            <form class="login-form">
              <label for="email">Email</label>
              <input type="email" name="email" id="email">
              <label for="password">Password</label>
              <input type="password" name="email" id="email">
              <button type="submit">Login</button>
            </form>
          </div>
          </div>
          <button class="link" id="signup">Sign Up</button>
        </nav>
        </div>
      </header>
      <script>
        const toggle = document.getElementById('toggle');
        toggle.onclick = function(){
          toggle.classList.toggle('active');
        }
      </script>
      </body>
    </html>](http://127.0.0.1:5503/index.html)
    

    Do you have a question here, @Apache, or any aspect you need help with?


    apache


    May 21, 2022, 2:01 PM


    #Four

    Yes, I posted the question on this thread after looking it up.


    apache


    May 21, 2022, 2:02 PM


    #Five

    body {
        margin: 0;
    }
    header {
      background-color: rgb(212, 209, 209);
      display: flex;
      flex-wrap: wrap; /* so navbar will go under logo on small smartphones */
      align-items: center;
      padding: 5px 4%;
      justify-content: space-between;
    
    }
    
    .logo {   
        margin-left: 20px;
        cursor: pointer;     
    }
    
    .nav {
        display: flex;
        gap: 1rem;
        padding: 0;
        align-items:center;
    }
    
    .link {
        background: none;
        border: none;
        text-decoration: none;
        color: #777;
        font-family: inherit;
        font-size: inherit;
        cursor: pointer;
        padding: 0;   
    }
    
    .dropdown.active > .link,
    .link:hover {
        color: black;
    }
    
    .link:last-child {
        margin: auto;
    }
    
    .dropdown {
        position: relative;
    }
    
    .dropdown-menu {
        position: absolute;
        right: 0;
        top: calc(150% + 0.25rem);
        background-color: white;
        padding: 0.75rem;
        border-radius: 0.25rem;
        box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .1);
        opacity: 0;
        pointer-events: none;
        transform: translateY(-10px);
        transition: opacity 150ms ease-in-out, transform 150ms ease-in-out;
    }
    
    .dropdown.active > .link + .dropdown-menu {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }
    
    .information-grid {
        display: grid;
        grid-template-columns: repeat(2, max-content);
        gap: 2rem;
    }
    
    .dropdown-links {
        display: flex;
        flex-direction: column;
        gap: .25rem;
    }
    
    .login-form > input {
        margin-bottom: 0.5rem;
    }
    #signup {
        
        padding: 10px 25px;
        background-color: rgba(0,136,169,1);
        border: none;
        border-radius: 50px;
        cursor: pointer;
        transition: all 0.3s ease 0s;   
    }
    


    apache


    May 21, 2022, 2:02 PM


    #6

    document.addEventListener("click", e => {
        const isDropdownButton = e.target.matches("[data-dropdown-button]")
        if (!isDropdownButton && e.target.closest("[data-dropdown]") != null)
        return
    
        let currentDropdown
        if (isDropdownButton) {
            currentDropdown = e.target.closest("[data-dropdown]")
            currentDropdown.classList.toggle("active")
        }
    
        document.querySelectorAll("[data-dropdown].active").forEach(dropdown => {
            if (dropdown === currentDropdown) return
            dropdown.classList.remove("active")
        })
    })
    


    Paul OB


    May 21, 2022 at 2:42 PM


    #7

    A toggle menu is in place, but with a different name. #toggle So you have to change your JS to reflect that.you called it #mobile menu.

    You haven’t actually styled the hamburger, so you should get the style to create the hamburger from where you saw that code.

    Once in place, set it to display:none by default and use media queries with the width you want to display. At the same point in the media query, change the style of the navigation to generally be below the header as desired.

    This is a basic start, but leaves you to fill in the gaps as you learn.

    #mobile-menu {
      display: none;
      height: 50px;
      width: 100px;
      background: red; /* just for testing - you need to find the correct css for this*/
    }
    
    /* I've used 800px as the trigger point but this needs to change based on the design */
    @media screen and (max-width: 800px) {
      #mobile-menu {
        display: block;
      }
      .nav {
        display: none;
      }
      .active + .nav {
        display: block;
      }
      /* Now from here you need to style the way you want that dropdown to look on small screen.
      This would probably be using absolute positioning to show the menu over any other content*/
      
      /* e.g. just for starters*/
      header {
        position: relative;
      }
      .nav {
        position: absolute;
        left: 0;
        top: 100%;
      }
      /* now adjust all the styling for the list elements as required*/
      /* ??? */
    }
    
     The js is changed to reflect the correct hamburger id.
    
    const toggle = document.getElementById("mobile-menu");
    toggle.onclick = function () {
      toggle.classList.toggle("active");
    };
    

    This is a basic start to get it working, so just style it as you wish 🙂


    apache


    May 21, 2022 at 2:51 PM


    #8

    Thank you very much, buddy. I really appreciate your unlimited support. you are correct. This code is left over from a previous project that I forgot to remove. But like you said, I try to figure out the rest, so the learning process becomes more effective.


    apache


    May 21, 2022 at 2:56 PM


    #9

    What about the html, do I need to make any changes or should I leave it as is?


    Paul OB


    May 21, 2022 at 3:09 PM


    #Ten

    Apache:

    What about the html, do I need to make any changes?

    You might be interested in the discussion in a similar thread that discusses using nested lists in html.

    Make some observations and then decide for yourself if it’s good to use. First, you should get rid of the inline click handler and run it from a JS file instead.

    The last example shows the difference when using nested lists. There’s nothing wrong with using regular html, but the nested list approach is much more extensible and allows unlimited nesting easier. If you are not following that approach, no need to change.

    Note that there are no hamburgers in this example, as we only discussed basic menus.

    Apache:

    Can you contact me if I get stuck?

    Of course, if you get stuck, just post.I’ll be out until Sunday afternoon, but I hope someone else jumps in by then. :slight_smile:



    1 like


    apache


    May 22, 2022 at 5:07 AM


    #12

    OK! Amazing. You mean this discussion with OBXjuggler? I don’t think there is a similar project.I needed the html code so I could combine it with the css code provided :hug:


    Paul OB


    May 22, 2022 at 12:55 PM


    #13

    Apache:

    I don’t think there is a similar project. I needed the HTML code

    In that discussion, I talk about nested lists and give an example of my preferred approach.The original html is similar to yours, useful for comparison

    You don’t have to copy the code, but understand the difference and help you learn. :slight_smile:



    1 like


    apache


    May 22, 2022 at 7:43 PM


    #14

    Haha! OK! Now I understand your intent. You’re right. Copying and pasting is not very effective learning. Instead, getting inspired and figuring out solutions is a much better way to learn programming.



    3 likes


    apache


    May 26, 2022, 2:40 PM


    #16

    Hello dear Paul,

    Back to you again with almost the same topic. I’ve tried it myself to make the website collapse into a vertical navigation menu with both dropdown buttons on the left side when the hamburger button is clicked. But I couldn’t accomplish this step. Can you help me with this problem?? Below you will find a link to the style I am working on in Example 2. :point_down: :point_down:

    https://mdbootstrap.com/snippets/jquery/mdbootstrap/911242

    index.html (2.5KB)
    style.css (1.7KB)
    script.js (1.0KB)


    Paul OB


    May 26, 2022 at 5:51 PM


    #17

    Apache:

    Below this you’ll find links to the styles we’re working on in Example 2.

    I copied the new code into my codepen and basically added the code I provided in the previous answer :slight_smile:

    I’ve styled the dropdown when the hamburger is open very loosely so you know what to do. It is not meant to be a finished product per se. I wouldn’t actually use the same html as you for the dropdown, but I would have used a more structured list approach and a more consistent button usage as described in my previous post.

    However, this demo serves as an example of how to implement a hamburger and start styling the dropdown. :slight_smile:



    1 like

    Apache:

    Hello everyone.

    I am currently learning how to make a website. I built a website using HTML CSS Javascript. I’m currently trying to learn how to collapse a website into vertical navigation as shown on this website.I’m attaching a link here so you can get an idea: https://mdbootstrap.com/snippets/jquery/mdbootstrap/911242#html – tab view

    I think bootstrap beats what you want by far. did you implement it?



    1 like


    apache


    May 29, 2022 at 7:43 PM


    #19

    OK! What does bootstrap mean?


    apache


    May 29, 2022, 8:06 PM


    #20

    OK! great. You’ve rebuilt almost exactly the design I wanted.I figured out how to make a hamburger button. However, I tried to move it to the right and toggle too many times, but to no avail.

    index.html (2.6KB)
    style.css (2.4KB)

    Obs! How can I submit my code to CODEOEN?


    Paul OB


    May 29, 2022, 8:40 PM


    #twenty one

    Apache:

    However, I tried to move it to the right and toggle too many times, but to no avail.

    I’ve provided the code for that, so I’m not sure what you’re asking?

    The CSS you posted doesn’t have media queries in place and fullscreen doesn’t hide the button. When I put the media query, the hamburger automatically moves to the right because it hides the navigation and moves the navigation to the new position.

    It looks like you got some other code for your burger, but I suggest you use mine and style it as you see fit. The hamburger code in your example looks like a checkbox hack and requires a ton of css to go along with it.

    I recommend working from my working code.

    Apache:

    OK! What does bootstrap mean?

    He probably means the framework you keep mentioning! Bootstrap5 is the latest version. I have a component that creates a hamburger and a dropdown out of the box.

    However, I don’t think it’s at a level where it can be used properly yet, as it has a steep learning curve and can be done without it if you really know how to use it.



    1 like


    Paul OB


    May 30, 2022 at 6:30 am


    #twenty two

    Apache:

    How can I submit my code to CODEOEN?

    Once you’ve signed up for a free account on codepen and your pen is complete, simply paste your code pen URL into a post here and your embedded pen will automatically appear. :slight_smile:



    1 like



    Source link

    Share this:

    • Tweet
    • Email
    • Pocket
    • Mastodon
    • WhatsApp
    • Telegram
    • Share on Tumblr
    • Print
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email
    Previous ArticleCross-country team enjoys ‘great season’ despite limited numbers
    Next Article Learn JavaScript with no coding experience for just $40
    websitebuildersnow
    • Website

    Related Posts

    The 2023 Nagaland State Budget presents state matching shares for the CSS for the first time.

    March 27, 2023

    XHTML: Should Doctype, Meta and Link be closed as single tags? – HTML and CSS – SitePoint Forum

    March 27, 2023

    Annual Development Outlay for 2023-24 fixed at Rs 82,000 lakh | MorungExpress

    March 27, 2023
    Add A Comment

    Leave a Reply Cancel reply

    Top Posts

    Subscribe to Updates

    Get the latest sports news from SportsSite about soccer, football and tennis.

    Advertisement
    Demo

    This website provides information about CSS and other things. Keep Supporting Us With the Latest News and we Will Provide the Best Of Our To Makes You Updated All Around The World News. Keep Sporting US.

    Facebook Twitter Instagram Pinterest YouTube
    Top Insights

    Clearview AI used nearly 1m times by US police, it tells the BBC

    March 27, 2023

    The Papers: Fight for union and 'crackdown on party houses'

    March 27, 2023

    Unboxing Is So 2012. The Internet Wants Packing Videos

    March 27, 2023
    Get Informed

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    © 2023 bestwebsite-builders. Designed by bestwebsite-builders.
    • Home
    • About us
    • Contact us
    • DMCA
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.