I have created a web page with uses a stylesheet which has the following class –
.div2 {
border:1px solid black;
width:75%;
margin:auto;
}
I have applied it to a div tag on the web page like this –
<div class="div2"></div>
When I view the web page in my browser, the class has no effect at all. Now, when I use inline CSS like this instead –
<div style="border:1px solid black;width:75%;margin:auto"></div>
and view the web page in my browser, the class is applied and works perfectly!
I am glad that it works but I would like to know why it works one way and not the other! Should both methods not result in the same thing happening? I have other classes on the stylesheet which all work so I have not had to use inline CSS anywhere else. Are there any circumstances where inline CSS needs to be used instead of a style sheet? Hope this makes sense!
.div2rule. Firebug would tell you if this is the case.border: 1px solid black;crossed out. If you see that then look for aborder: ...rule that is not crossed out to find the CSS rule that is overriding what you want. Get more specific than that rule.