Reputation: 627
can some one explain why the following happens:
<a href="#" class="test">Test</a>
<style type="text/css">
.test {
border: thin solid blue;
color: red;
}
</style>
This only creates the border but doesn't turn the text red when using a class.
However, this works in turning the text red when using an id instead:
<a href="#" id="test">Test</a>
<style type="text/css">
#test {
border: thin solid blue;
color: red;
}
</style>
Why does the class not change the text color, while using id does work?
Thanks!
Upvotes: 0
Views: 19063
Reputation: 4104
try changing the style tag into this:
<style type="text/css">
a.test{
border: thin solid blue;
color: red;
}
</style>
Upvotes: 1
Reputation: 13967
See this example: http://jsfiddle.net/mD5us/4/
<div>
<a href="#" class="test">Test</a>
</div>
CSS
body div a.test{
color:yellow;
}
body div .test{
color:brown;
}
body a.test{
color:purple;
}
body .test{
color: orange;
}
a.test{
color:green;
}
.test {
border: thin solid blue;
color: red;
}
You might think that the link will be red, but it will actually be yellow since that is the most specific declaration.
Upvotes: 2