css - When do I use class/id and when do I target the html tag directly -


hello ladies , gentlemen,

i have (another) question concerning html/css best practices. checked web , site came articles on when use ids , when use classes. however, that's not struggling with.

i know when use class selectors on html element selectors , vice versa.

example:

html

<div class="container">     <p class="nested-p">feefifem</p> </div> 

css option 1:

.nested-p{...} 

css option 2:

.container p{...} 

which option preferable under circumstances , why?

the first option .nested-p classes ( can put class html ,body , p ,div , aside etc --- - want.)

the second 1 p under .container ( yeah , that's right , p)

regarding priority - second 1 higher (read this )

why ?

becuase of :

enter image description here

a few pasted drawing (just emphasize)

enter image description here

so second 1 :

enter image description here

while first 1 like:

enter image description here


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -