scottybwoy Posted December 6, 2007 Share Posted December 6, 2007 How come sometimes a styles invoked via a class don't work, but when put in the style of the element they do? eg: element.class { right:5px; } //not working <element style='right:5px;' /> //working Quote Link to comment https://forums.phpfreaks.com/topic/80443-quick-question-styles-vs-class/ Share on other sites More sharing options...
phpQuestioner Posted December 6, 2007 Share Posted December 6, 2007 It should work either way if your CSS is correct, but inline styles always dominate over other style options. Quote Link to comment https://forums.phpfreaks.com/topic/80443-quick-question-styles-vs-class/#findComment-408285 Share on other sites More sharing options...
mainewoods Posted December 7, 2007 Share Posted December 7, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/80443-quick-question-styles-vs-class/#findComment-408590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.