If you have an HTML page with a class in an element, for instance <div class="myClass">, would it be best to refer to it in the CSS as .myClass or div.myClass?
If you have an HTML page with a class in an element, for instance
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
div.myClassmakes the style declaration more specific. In other words, it takes higher priority. So, it’s sometimes a good thing to specify it in order to avoid CSS conflicts when you’ve got many developers onboard a project and people add classes like there’s no tomorrow. In other words, if you’ve got Bob adding:and Sarah adds:
Sarah’s class will trump Bob’s class when you’ve got:
You can get make it even more specific by specifying it with the ID, but that’s sort of outside the scope of your question. 🙂