Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Interactive Rating Component using Flexbox

renko7 50

@renko7

Desktop design screenshot for the Interactive rating component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Hello!

I difficulty in organizing my class names within the HTML and CSS. I am still not sure if I should be giving everything individual classes or making heavy use of selectors. If you can tell me the best practice that would be highly appreciated. As for example for my queryselectors was I supposed to just use one class? Also for my CSS was I supposed to just use once class?

I also had a question about the light grey background that was behind the rating numbers and the star. All of the colors that I tried from the style guide were not working like that! So maybe the background is being set some other way? You will see that I just went with the dark background in the end.

Thanks ALOT for your help!

Community feedback

P
Dave 5,245

@dwhenson

Posted

Hi renko7 - regarding your question on CSS and class names, frustratingly, the answer is: it depends! This is something I struggled with for a long time, and I was worried that I wasn't doing things the "right" way. I know it's dull advice, but if you keep building things and learning and trying different approaches you will find something that works for you.

For example, many people love Tailwind CSS, which I'd also like to try one day, which applies classes inline to each individual element, other people like a BEM approach, which moves towards removing the complications of the cascade. Personally, I love, CUBE CSS, which embraces the cascade and maps nicely to how I think about CSS.

But don't worry about trying all these things, or even if you haven't heard of them, for the moment if you are just getting started just enjoy building things, getting stuck, finding solutions, and asking for advice when needed. It took me quite a while to settle on an approach to CSS that works for me, and it's always changing.

Kevin Powell's responsive layout course that is free on Scrimba is a good place to move to once you have the hang of basic selectors.

Here are a few comments with regard to your code:

  • I would check whether an element is actually a button or a link. The most important thing is what the element will do not what it looks like. This page has a great summary and lots of useful links on this: https://css-tricks.com/buttons-vs-links/ (I think you have this wrong that the moment!)
  • Good choice with the radio buttons, to make things nicer could you add a transition on the hover to make the color change a little less abrupt? And I would suggest adding the curser:pointer to the CSS for this element - not everyone would agree, but I think it's kind of expected for this type of interaction.
  • Lastly on the JS I would advise against using class names as the basis for selecting elements. This has caused me so much headache in the past, as when you start adding and removing classes the JS stops working! I try to use data- attributes when possible as I know that I can keep them just for this purpose.

Good job and keep up the good work!

Cheers Dave

Marked as helpful

2

@GrzywN

Posted

Great job on the challenge!

Regarding your question there are many ways to handle connection between HTML and CSS. As @dwhenson said there are many approaches and everyone have to choose what fits him the most. But connection between HTML and JS can be handled (especially functionality changing on user actions) using dataset properties and sometimes aria attributes. I really like this approach and I use it all the time while creating functionality of website apps. You can create your own attributes with data-* prefix and control them with JS and style with CSS selectors like .class-name[data-example="true"]. I recommend you to try it ! HTMLElement.dataset

Keep up the great work. Have a nice day and happy coding!

Marked as helpful

1

Please log in to post a comment

Log in with GitHub
Discord logo

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