-4

Given the HTML snippet:

<div class="class"></div>

What's the difference (& consequence) between the styling (CSS):

  1. div.class
  2. div .class

N/B: There is white space between div and .class in (2), but not in (1).

j08691
  • 204,283
  • 31
  • 260
  • 272

2 Answers2

0

The first example selects all divs with the class "class".

The second example selects all descendant elements of a div that have the class "class".

So your example HTML would only be selected by example 1 (unless the HTML was a child of a div, in which case example 2 would also select it).

j08691
  • 204,283
  • 31
  • 260
  • 272
-2

You should do research before asking questions on SO. You could have found the answer you were looking for with one Google search, here is the answer:

div.class: Selects all div elements with class="class"

div .class: Selects all elements with class that is a descendant of an element with div

Taken directly from W3 Schools CSS Selectors

Doga Oruc
  • 783
  • 3
  • 16
  • 1
    _"Selects all elements with both div and class set within its class attribute"_ Incorrect – j08691 May 19 '21 at 16:02
  • W3 schools..., nevertheless, I do believe they should have googled it for a minute, or half a minute to find the solution. – prettyInPink May 19 '21 at 16:04