Reputation: 2713
Cant seem to get a class to over write the inherited styles for a:link
@Html.ActionLink("Back to List", "Index", null, new { @class = "htmlactionlink" })
CSS
a:link, a:visited,
a:active, a:hover
{
color: #333;
}
.htmlactionlink {
color: red;
}
Doesn't effect the style of the element?
If I apply a inline style, it works.
Upvotes: 1
Views: 3907
Reputation: 123861
The answer is in understanding the CSS: 6.4.3 Calculating a selector's specificity. Small Extract
A selector's specificity is calculated as follows:
Other words:
The point 3. says, that the same value for precedense is applied to class and pseudo-class (see more in w3schools.com)
It means, that calculation for
a:link is { a=0, b=0, c=1, d=1}
while
.htmlactionlink is { a=0, b=0, c=1, d=0}
And that's why the a:link
statement takes the precedence, because it takes 1 point for class and one for element name.
NOTE:
from my perspective the most correct solution is the
.htmlactionlink:link, .htmlactionlink:visited ... {
color: red;
}
In that case, we do get {c=2, d=0}, we do not count on the order as with a simple A.htmlactionlink
{c=1, d=1}
Upvotes: 3
Reputation: 15866
try
a:link, a:visited,
a:active, a:hover
{
color: #333;
}
a.htmlactionlink
{
color: red;
}
Upvotes: 0