0

I am curious to know the usage of the div.something in CSS. I have seen this around the Internet but don't know what it really means when people use div. following by some class without gaps. What is it?

div.report {
    background:pink;
}

This seems the same thing like .report { .. } so why would some one use div.report

0

3 Answers 3

3

div.report means that only div elements with the class of report will be selected. .report on the other-hand will select any element with report class, be it a div, p, span, etc.

Additionally, div.report is more specific than .report, so properties in the former will override properties in the later.

Sign up to request clarification or add additional context in comments.

1 Comment

This answer adds an important extra detail about specificity.
1

This CSS rule matches div elements with the class report. If you omitted the div then it would match any element with the class report.

1 Comment

Right, I get it. It makes sense. Thanks.
1

In case you also have <span class="report">.

Or, simply to clarify to people reading the CSS what elements will have that class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.