Skip to content Skip to sidebar Skip to footer

Multiple Divs With The Same Id Applying Css Style Works Same Like Class?

I'm confused about the class and id selection with css if i have multiple divs with same ID changeing ID to Class does not have any effect on the result style

Solution 1:

First of all, using multiple times the same id is invalid. Never do it.

Then, in css selectors, you need to use

  • ".whatever" to target classes
  • "#whatever" to target ids.

Here is an example.

<!-- in HTML --><divid="identifier1"></div><divclass="class1"></div><divclass="class1"></div>

/* In css */
#identifier1 { /* This targets the first div */ };
.class1 { /* This targets the second and third div */ };

Post a Comment for "Multiple Divs With The Same Id Applying Css Style Works Same Like Class?"