Reputation: 49
I have code with some <li>
in <ul>
Here is it
<ul class="nav navbar-nav navbar-right" style="color:black;">
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
I need to change color of <li>
to black
I try to do it like this style="color:black;"
This is ASP.NET code
Here is genereted code
<ul class="nav navbar-nav navbar-right">
<li style="color:#000000;"><a href="/Account/Register" id="registerLink">Register</a></li>
<li style="color:#000000;"><a href="/Account/Login" id="loginLink">Log in</a></li>
</ul>
But color didn't changed.
How I can change it?
Upvotes: 1
Views: 371
Reputation: 916
add class inside 'htmlAttributes' in ActionLink.
@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink", @class = "aclass" })
And inside your css:
/* Class of 'a' element
.aclass {
color: black;
......
}
This should work.
EDIT: You must use '@', because class is a keyword in C#. Link to the MSDN documentation:
Upvotes: 2
Reputation: 194
This should work:
<ul class="nav navbar-nav navbar-right">
<li style="color:black;">@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li style="color:black;">@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
However, since it looks like you are rendering an anchor-tag inside the <li>
, they might not be black. Since you can't add the style-attribute to the anchor tags, you will have to add this CSS:
ul.navbar-nav a {
color: #000;
}
Upvotes: 1