Ali Gajani
Ali Gajani

Reputation: 15091

Why use class AND element type in a CSS selector?

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

Upvotes: 0

Views: 90

Answers (3)

SLaks
SLaks

Reputation: 887415

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

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

Upvotes: 1

Alexander O&#39;Mara
Alexander O&#39;Mara

Reputation: 60527

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.

Upvotes: 3

Jason Sperske
Jason Sperske

Reputation: 30416

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.

Upvotes: 1

Related Questions