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

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -