Richard77
Richard77

Reputation: 21609

Asp.Net-MVC: How to style <%=Html.ActionLink()%> with Css?

Here's a piece of my HTML code

<div id = "mydiv">
    <% = Html.ActionLink("Some Text","SomeAction")%>
</div>

I'd like to style it in white so that it doesn't conflict with the background, which is also blue. So I did this:

#mydiv {background-color:blue;} 
#mydiv a:link { color:white}

But, it doesn't work -- the color it's still blue. How can I do it? Maybe, I just did not write well the selectors.

Thanks for helping.

Upvotes: 10

Views: 32812

Answers (7)

Rohit
Rohit

Reputation: 6613

In my case this one worked

HTML.ActionLink("LinkLabel", "ActionName", "Controller", null, 
               new {@class="btn btn-primary pull-right"})

If I don't use null above the proper controller action i.e. Controller.ActionName method was not called. Instead something like currentController/Length==4 something like this was called.

Upvotes: 5

Dkong
Dkong

Reputation: 2788

Mine is like Luke's but I have a null in there (I'm using MVC2)

<%=Html.ActionLink("Text","Act","Ctrl",new {@style="color:white;"}) %>

Upvotes: 5

Richard Szalay
Richard Szalay

Reputation: 84724

Remove the :link suffix and you should be fine:

#mydiv { background-color:blue; }
#mydiv a { color:white; }

Alternatively you can add a class name to the link:

<div id="mydiv"> 
    <%= Html.ActionLink("Some Text", "SomeAction", 
            new { @class = "class-name" }) %> 
</div> 

Upvotes: 10

luke
luke

Reputation: 245

Maybe

<%=Html.ActionLink("Text","Act","Ctrl",new {@style="color:white;"}) %>

Upvotes: 9

JonoW
JonoW

Reputation: 14229

Try:

#mydiv a { color:white}

Also, try remove the whitespace around your Id attribute (just in case): ->

Upvotes: 1

Fermin
Fermin

Reputation: 36071

Try removing the :link and just having

#mydiv a { color:white}

this should colour the link white.

I'd recommend using the Firebug plugin for firefox also, this allows you to change the stylesheet and see instant changes as well as see which styles are being applied to each element, which styles are being 'overuled' by other styles etc.

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

#mydiv a { color:white; }

Upvotes: 10

Related Questions