Interactive Rating Component (HTML, CSS and JavaScript)
Design comparison
Solution retrospective
Don't know why but cannot centre divs easily.
Found it difficult to target array (buttons in ("body .rating") and apply 'onclick' in javascript. Apparently you can't apply 'onclick' to querySelectorAll etc. So you need to create a for loop / function and apply it to that? Any feedback would mean a lot!
Community feedback
- @Toluwaa-oPosted almost 2 years ago
Well done on completing the challenge.
Concerning centering divs, you can use a few different methods. The first one is to set the margins to auto, the second method requires setting the display property to 'grid' and then setting 'place-content' to 'center'. The third method requires setting the display property to 'flex' and then setting the 'justify-content' and 'align-items' property to center. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container
Concerning your other question, querySelectorAll returns a nodeList. So you can either use a for loop or you can use the index (first one is 0) to select individual items in it. You can find more information here: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
Marked as helpful1 - @CreolaTudorachePosted almost 2 years ago
I remember i struggling a little bit too for this and i find out about inline-block, padding inline. About JS i find a easy way to write my code. I declare a variable without any value and i made a for each with 2 properties and i count+ the variable in this function. You can see my code here and maybe it will help you to understand.
https://github.com/CreolaTudorache/rating-card-js/blob/master/index.jsMarked as helpful0
Please log in to post a comment
Log in with GitHubJoin 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