I’m learning CSS and was just wondering which way is best when writing CSS:
div.divname or .divname
ul#menu or #menu ul
etc etc
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.
There’s a difference between every element you’ve specified.
div.divnameWill match all divisions with the class name ‘divname’.
.divnameWill match all elements (divisions, paragraphs, anchors, everything) with class name ‘divname’.
ul#menuWill match the unordered list that has the ID ‘menu’.
#menu ulWill match the unordered list that is contained within the element with the ID ‘menu’.
Other than explaining these, I don’t know exactly what you’re trying to do. All I can recommend is avoid specifying class names that can match to any element as much as possible, and remember that only one element can have a specific ID inside a single document. From the first example,
div.divnamewould be better. From the second example, they are both completely different.