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

Interactive Ratings Component

Benny Heo•30
@bennyheo
A solution to the Interactive rating component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I didn't know how else to change states so I set both sets to an absolute position and hide the 'Thank you' card. Is this the correct way to do something like this? The alternative seemed like a bunch of DOM manipulation which seemed impractical.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Reddsito•210
    @Reddsito
    Posted almost 3 years ago

    Hello, I will not be the most experienced but, the way I make the change is simply that, when an option is already selected, when pressing the "submit" button add a class to the main box, for example "--active" and I make that when that box has that class, do display: none to all the div, except the one I want to show, I don't know if it's more practical but it's an option :D

  • Amélie•330
    @aweliego
    Posted almost 3 years ago

    Hi Benny,

    There are many, many ways to accomplish this with vanilla JavaScript and CSS. Part of what one might consider a solution more correct than another might be the side effects caused by the chosen method. Mostly, with the 'position absolute' method (which I've also used, btw) is that the element with position absolute will remain visible in the DOM, but this harms accessibility as absolute positioning overrides the default flow layout of browsers. From what I understood, this would also be the case if you would try to tweak the visibility/opacity or use transform properties (such as translate() or scale()) to make the element disappear from sight. [Please someone correct me if I'm wrong]. From what I've found, only changing the display from block to none will effectively remove the element from the DOM and thereby provide a better experience for all users. The WebAIM provides a good thought starting point on the topic: https://webaim.org/techniques/css/invisiblecontent/

    That being said. Targeting the display property won't allow for CSS transitions (in case you'd want to add some to switch from one card to another) as it is not possible to animate/transition from display: block to display: none. Therefore I found it is tricky to accommodate accessibility and transitions, but I'm sure there are ways to do this, just haven't looked for them at this point.

    Regarding your solution for this particular point: I'm not sure about the necessity to position the rating tool card absolute. If I remove that property in the dev tools, it seems to be hiding the attribution div, but if you delete that one you have no need for the absolute position anymore.

    Some more feedback:

    • I think the colour scheme for the buttons on hover/click is reversed: they should actually be greyed out when you hover over them and the one that is click should change to (and remain) orange :)
    • I would make the cursor a pointer when hovering over the rating and submit buttons

    Other than that, your code looks quite DRY and you used both Grids and Flexbox which is interesting - good job on this challenge!

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