Why the below two codes shows different styles ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Why the below two codes shows different styles ?

First code is #intro .p em{ color:red;} . Second code is #intro.p em{color:red;}

10th Jul 2018, 2:40 AM
Ugyen Chophel
6 Answers
+ 3
The first code is for element #intro with child p class, sub-child em tag. eg. it would select "selected" from below HTML <div id="intro"><div class="p">This is <em>selected<\em><\div><\div> The second is for <div id="intro" class="p"><em>selected<\em><\div>
10th Jul 2018, 3:25 AM
Calviղ
Calviղ - avatar
+ 2
Calviղ You're right. I always get spaces and commas mixed up. Thanks.
10th Jul 2018, 3:40 AM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 1
The first one applies to any element with the id "intro", the #intros child class "p", and the .ps child em element. The second applies to any element with the id "intro" AND class "p", and the em tag.
10th Jul 2018, 2:59 AM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 1
Ben Allen (Njinx) The css selector that select any element with id "intro", class .p and em element is $intro, .p, em { }
10th Jul 2018, 3:28 AM
Calviղ
Calviղ - avatar
+ 1
Rose Sevenyears Yes, there is the common way developers use to addrees an element.
11th Jul 2018, 11:03 PM
Calviղ
Calviղ - avatar
0
Calviղ And maybe others? Isn't it possible to do : <p class="p" ></p> ?
11th Jul 2018, 9:52 PM
Reinier Caron
Reinier Caron - avatar