Class Selector Rules

Hi guys :slight_smile:

May you kindly please explain when you are allowed to use a period before a “class” selector and when are you not because I have had instances where it would give me an error message if there’s no period (,) at the beginning of the “class” selector.

For instance: address / .address

I really appreciate the help & support you guys.

if there’s no period (.), I meant…

Putting a period before something means you are targeting a class with that name. So .address would mean you are targeting all elements that have a class of address.

Without the period you are targeting the element itself. So address would mean you are targeting any address element on the page.

1 Like

This makes total sense.

Please check the below attached solution.

.img {display: block;
      margin-left: center;
      margin-right: center;
}

This resulted in an error as it was targeted at a particular image. So, now I get it.

Thanks a lot :slight_smile:

<img> is not a class. It is an element and so you do not use
class selectors for classes example class="abc" that are within an element.
Thus you do not use the dot notation for class selectors

1 Like

Hey Adam :slight_smile:

Yeah, now I get the concept.

Appreciate the feedback :pray:t6:

If you may please check out the topic I just posted now regarding a new challenge.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.