Order summary component card with plain HTML & CSS
Design comparison
Solution retrospective
I actually made this a few months ago when I only knew html & css, and if I did it today I would probably do it with React.
all feed back welcome!
question: have I over-used or under-used the id attribute? how often should you use it in best practice? Is this even a consideration when using frameworks like React?
Community feedback
- @seanred360Posted over 2 years ago
The answer your question: React does not have an opinion about your css. It is a javascript library that keeps the virtual DOM in sync with the real DOM. You can use css, scss, styled components, inline styles, styled JSX, React does not have an opinion about that.
IDs are used in CSS to make a rule more specific than a class. I rarely use IDs because I rarely need to have something so specific. I always use class as a default. If I for some reason need to target something very special that is one of a kind in the whole app, I might use an ID. An example could be maybe you have many buttons on your site with the classname of 'btn'. You want them all to be the same size and font, but you have a very special submit button that you want to change it to be green. You do not need ID for this. You can put the class 'btn' and another class called 'green' on it. Then in CSS you can target '.btn .green' to target that button. Then if you went a step further and you have several buttons with '.btn .green' you could target one of them with an even more specific rule like an ID. The ID will override the styles in '.btn .green'.
In conclusion, using IDs is a personal preference. I do not like to use them because if I begin with an ID, how can I get a more specific rule above that if I want to override the styles?
Marked 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