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

Mobile First Workflow FAQ According Card Solution with CSS Grid

sass/scss
Achref KS•530
@AchrefFast
A solution to the FAQ accordion card challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Hi everyone,

The way I handled the "Hide/Show the answer to a question when the question is clicked" part with JavaScript seemed to me not straightforward. Is there any better way to deal with it?

Any advice, suggestion or feedback would be a big help.

Thanks.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Dave•5,295
    @dwhenson
    Posted over 3 years ago

    Hey @AchrefFast great work on this one!! You've got the images positioned well and it's nice and responsive.

    One thing that really helped me with this one was the use of the details and summary HTML elements. These have much of the functionality baked in and can be styled with a little bit CSS work. This also has the advantage of including keyboard functionality and allow the key elements to be focusable automatically (which is currently missing from your solution).

    If you went with this approach you can also animate the opening and closing pretty simply using some code like:

    details[open] summary ~ * {
    	animation: sweep 0.2s ease-out;
    	will-change: opacity, transform;
    }
    
    @keyframes sweep {
    	0% {
    		opacity: 0;
    		transform: translateY(-1em);
    	}
    
    	100% {
    		opacity: 1;
    		transform: translateY(0);
    	}
    }
    

    The styling of these elements can seem a bit complicated at first, but there are some good resources out there. The page is a bit of a mess but I have found the following page to be a pretty good guide in how to style things, including the triangle indicator: https://webdesign.tutsplus.com/tutorials/explaining-the-details-and-summary-elements--cms-21999

    Great work though and I hope this helps.

    Cheers Dave

    Marked as helpful
  • Aakash Verma•9,500
    @skyv26
    Posted over 3 years ago

    Good work..

    What you have done is ok there is no problem, because you can hide and show faq using only css, but it is not possible to show one faq and hide all, it is only possible using JavaScript.

    Don't worry , feel proud what you have learnt, move on to next

    Marked as helpful
  • Achref KS•530
    @AchrefFast
    Posted over 3 years ago

    Hi Dave,

    I really appreciate your time for giving me your feedback, this was a big help.

    Actually I didn't know about the details element before, this was the first time I heard of it, so thank you for mentioning it.

    As a result, I decided to use your approach instead of the simple div, and working with it everything became much easier. I didn't have to worry about the hide/show feature anymore, since its embedded within the details element by default. Also, adding the animation come to be more simpler with the help of the details[open] attribute selector.

    I managed to add these features to my solution:

    1. Keyboard access functionality.
    2. Animate the opening of the question.
    3. Show the selected question and hide the others.

    Thank you so much for your advice and sharing your experience, this helped me a lot.

    Best Regards,

    Achref

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

Oops! 😬

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

Log in with GitHub