This is a solution to the Intro section with dropdown navigation challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View the relevant dropdown menus on desktop and mobile when interacting with the navigation links
- View the optimal layout for the content depending on their device's screen size
- See hover states for all interactive elements on the page
- Repository URL: Repository
- Live Site URL: Demo page
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
- CSS Grid
- Mobile-first workflow
Below is the code to handle the dropdown menu in mobile version, including the transition setup.
CSS code to style mobile dropdown
.sub__section { max-height: 0; height: fit-content; overflow: hidden; transition: max-height 500ms ease, margin 100ms ease 400ms, padding 0ms ease 300ms; padding-left: 1.5rem; } .sub__section.expanded { max-height: 200px; margin-top: 2rem; transition: max-height 500ms ease, margin 250ms ease 0ms; }Js function to handle dropdown
const arrows = $$('.arrow'); arrows.forEach(arrow => { arrow.addEventListener('click', e => { const subSectionClasses = e.target.parentElement.lastElementChild.classList subSectionClasses.toggle('expanded', !subSectionClasses.contains('expanded')); arrow.src = !subSectionClasses.contains('expanded') ? '../images/icon-arrow-down.svg' : '../images/icon-arrow-up.svg' }) })My layout skills still needs a bit of improvement. I'll keep using some time making pages and sites which need good layout skills to work on them.
- Website - Daniel Portillo
- Frontend Mentor - @dportillo23
- Twitter - @DaniDev23

