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

Intro section with dropdown navigation

Abdul rehman•650
@abymani
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


Setting navigational menu was difficult for me . I think my javascript code is not optimal it does work but there must be a way to do it better. any suggestions will be appreciated.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • lieneil•560
    @NJVS
    Posted almost 3 years ago

    Hi, Abdul. Congrats for completing the challenge.

    Regarding your dropdowns, I've notice that the <li id="features"> and <li id="company"> has the same click event. You can just assign a identical class name for your dropdown like this <li class="dropdown"> then select both of them in javascript then run a forEach() method then add click event(thats a lot of "then" LOL). Also, instead of toggling class for sub-menu, <a> and <i class="fa-solid">, I suggest to just toggle a class on their parent element.

    const dropdowns = document.querySelectorAll("li.dropdown");
    
    dropdowns.forEach(dropdown => {
      dropdown.addEventListener("click", function(event) {
        event.currentTarget.classList.toggle("active");
      });
    });
    
    .dropdown.active > a {
      font-weight: 700;
    }
    .dropdown.active > a i.fa-solid {
      transform: rotate(180deg);
    }
    .dropdown.active > .sub-menu {
      display: block;
    }
    
    Marked as helpful
  • Chyunjet•620
    @Jetyun
    Posted almost 3 years ago
    1. the Accessibility issue, you can put header tag to contain all the tag that is not in the main tag.
    2. for HTML, i can only comment on the img tag issue, where you no need to put unit on the width and height (the system knew that it is pixel)

    on design:

    1. I think you missed the active state on certain button (career, about, login, register and learn more)

    2. On the greyed out section in the mobile view, i actually used a div with position: absolute with background color of almost black paired with opacity setting to recreate the design. the div, you can just put above the big picture, no need to put anything in the div tag. Then just use JS to amend the display between none and block when you clicked the menu icon. remember to set the width and height of the div so that the grey area actually covered the same area in the design.

    Marked as helpful
  • Abhilashpandey•270
    @freakyjones
    Posted almost 3 years ago

    Hi Abdul,

    congrats on completing the challenge

    I just saw your code, I would like to give some suggestions with your permission

    1. start using data attributes in your code, It will be much more efficient to change open and hide the nav and reduce the use of excessive javascript.
    2. try using a z-index while stacking multiple components in one place . Here is one of my favorite videos regarding z-index (https://www.youtube.com/watch?v=uS8l4YRXbaw).

    hope it helps, Thanks Happy coding :)

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 all CSS, SCSS and Less files in your repository.

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.

How does the JavaScript validation report work?

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

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

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

Oops! 😬

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

Log in with GitHub