1

I checked the link at Asp Button hover and CSS but to my frustration, I still couldn't find a solution to apply CSS to the hover state of my ASP.NET button.

My button is declared like so:

    <asp:Button ID="btnRegister" runat="server" 
                 onclick="btnRegister_Click" CssClass="btnRegister"/>

My CSS for the button is:

.btnRegister {
    background-color:#FFF;
    color:#000;
}
.btnRegister : hover{
    border:solid 2px #000;
}

.btnRegister : active{
    background-color:#000;
    color:#FFF;
}

When I inspected the button in FF and IE, I saw the styling is only done on the button, not on the button when hovered.

Furthermore, I have a skin file applied to the page which holds the button but it is applied to other controls, not the button.

Anyone got any ideas on how to access the hover state of the button?

3 Answers 3

5

take out the extra blank spaces between the class name and the pseudo-state:

.btnRegister {
background-color:#FFF;
color:#000;
}
.btnRegister:hover{
border:solid 2px #000;
}

.btnRegister:active{
background-color:#000;
color:#FFF;
}
Sign up to request clarification or add additional context in comments.

Comments

3

Hey, just remove the space before and after the 'hover' and 'active', and you get it.

.btnRegister:hover
.btnRegister:active

Comments

1

jQuery

$("button").hover(
  function () {
    $(this).css("your style");
  }, 
  function () {
    $(this).css("origin style");
  }
);

Hope this can help.

3 Comments

I tried and it did work but I wanted to keep it simple. Thanks for the correct suggestion though.
@fred It seems like IE only supports a:hover. So you want to use css to achieve the goal may be a little difficult.
That's true...I just found out about that...sigh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.