Jump to content

Quick question styles vs class


scottybwoy

Recommended Posts

they have this css precedence formula that goes like this:

 

inline style = 1000

id tag = 100

class tag = 10

redefine an html tag like a td = 1

 

now say I have a css definition like this:

#ID1 #ID2 a { color:red; }

the precedence value of that would be 201, 2 IDs plus one html redefinition

 

if I then had this code that uses the css definition above:

<div id="ID1"><div id="ID2"><a href="" style="color:green;">test</a></div></div>

--that link will be green not red! that's because the style tag has a precedence value of 1000 and beats the 201 above.  You can use the formula above like I used to figure out the precedence of what style beats what when conflicts occur.  Whoever has the highest total will win!

 

Since the inline style tag is closer to the code, the standards people determined that it should always wins.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.