As long as I am using one tag, I could just style it using nav {
style here } right? I don't necessarily need to use an id for it.
Yes and no!
Yes, you are right. If there's only one tag, css nav selector is enough to uniquely select that nav. But that's it.
No, CSS cascades and also have regular and "hidden" inheritance with * and >. So your nav might be selected elsewhere with > or * without you knowing it.
However the the position style does not work with the <nav>
.
Is there a reason for that, or should I always use id's even with a <nav>
??
Yes there is a reason. ID have second highest selection value. Html tag has lower selction value.
CSS Specificity in 4 columns:
inline=1|0|0|0, id=0|1|0|0, class=0|0|1|0, element=0|0|0|1
Left to right, highest number takes priority.
0,1,0,0 > 0,0,10,10
1. inline
2. num of #ID
3. num of .class
4. hum of html element selectors
0. JavaScript (dom inline + last = strongest selection)
Read more here.
Try this position: fixed !important;
If it doesn't work, try unique id with !important;
for that nav. If that solves the problem, you'll know it's all about specificity in selectors.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…