Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 1 year ago

FAQ-accordion (HTML and CSS only)

mingen898•10
@mingen898
A solution to the FAQ accordion challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Hello! I just finished learning the basics of HTML and CSS so I wanted to get some practice in. This is my first-ever challenge on GitHub! Unfortunately, I haven't learned Java Script yet so I couldn't make this website interactive, so here's the design part! I've had some trouble trying to fit the background pattern into the top part of the page, which is why my CSS code for it is messy. I made the width of the image 100% so that it covers the entire width of the page, at the same time trying to make the height smaller. But doing so made the width of the image smaller even though it's still 100% and I don't understand why. Any feedback would be appreciated!

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Muhammad Zariyan Asif•150
    @MuhammadZariyanAsif123
    Posted over 1 year ago

    Hi,

    You can fixed this issue by setting the body with background-image with this pattern and background-repeat = "no - repeat" something like this.

    In CSS FILE:

    body { background-image: url("your image"); background-repeat: no-repeat; }

  • Weston Vincze•30
    @WestonVincze
    Posted over 1 year ago

    Great job taking the first steps to learning web development!

    Responsive "hero" images are a bit tricky. The reason the height changes is because if the width is 100% the only way to maintain the correct aspect ratio is to shrink the height. There are many approaches to solve this problem, each with its own trade off.

    I solved this problem by setting a fixed height for the background-image and aligning it to the top center of the page. That way as the screen shrinks the image height stays the same and the edges get cropped. The reason I chose this solution is because I wanted to ensure that the FAQ section and hero image retained their overlapping positions.

    Also, HTML5 has relatively new <details> and <summary> elements that can create collapsible content (like an accordion) without the need for JavaScript. The browser support is somewhat limited but that's not a problem for a task like this.

    // details is a wrapper element
    <details>
      // summary is where you would put the "question"
      <summary>
        (question)
      </summary>
      // anything inside details and outside of the summary tag will be hidden or shown when the summary is clicked
      <p>
        (answer)
      </p>
    </details>
    

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