Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

intro-section

react
Marco•320
@marcoberdiano
A solution to the Intro section with dropdown navigation challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Finally i managed to make the hamburger menu working! Happy with my progress.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Marco•320
    @marcoberdiano
    Posted almost 3 years ago

    Hello Marge C. Thanks for your the suggestions. I did exatly what you propose but still have some problems. But i'm working on it, i made some progress.

  • P
    Marge C.•440
    @msunji
    Posted almost 3 years ago

    Heya Marco! I know responsive nav bars aren't always the easiest, so great job on this challenge! 👍

    I checked out your code and this is what I've done for the menu.

    • Instead of using checkSize and the useEffect hook to toggle your menu, you can use CSS classes. In your media query in NavBar.css, set nav-links to display: none, but also create another class called active with display: flex as a declaration. Something like this:
      .nav-links {
        // your other CSS declarations
        display: none;
      }
      .active {
        display: flex;
      }
    

    The idea here is that when you click on the hamburger menu icon, you want to toggle some piece of state which should then set or not set the active class.

    • Add a class to your hamburger icon, then in NavBar.css, set it to display: none on larger screen sizes and display: block on smaller screen sizes. This way the hamburger icon only shows up on smaller screens.
    • In NavBar.jsx, set showMenu's default state to false and then make an event handler handleMobileMenu that toggles the showMenu state value. Then add an onClick event handler to your hamburger icon div and pass handleMobileMenu to it. It'll look something like this:
      const handleMobileMenu = () => {
        setShowMenu(!showMenu);
      };
    
    <div className="hamburger" onClick={handleMobileMenu}>
    // your icon
    </div>
    
    
    • By the way, I imported NavLinks into NavBar.jsx instead of NormalMenu, then revised your code, so the end product looks like this (which I'll explain a bit below):
        <div>
          <nav className="nav-container">
            <div className="logo">
              <img src={logo} alt={logo}></img>
            </div>
            <NavLinks showMenu={showMenu} />
            <div className="hamburger" onClick={handleMobileMenu}>
              <img src={iconMenu} alt={iconMenu}></img>
            </div>
          </nav>
        </div>
    
    • Pass the value of showMenu to your NavLinks component. You'll use this to toggle the active class you made earlier.
    • In your NavLinks component, toggle the class name like so:
    <div className={`nav-links ${showMenu ? 'active' : ''}`}>
    // your code
    </div>
    

    This should sort out your issue for the most part, but for positioning and stuff, I'll leave that to you. Sorry this explanation got super long! If it's not very clear and you have any questions, feel free to reach out to me. Hope this helped!

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit 1st-party linked stylesheets, and styles within <style> tags.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub