4

So, it's pretty easy to set a hover over effect for an element. But what I want is when the user hovers over a button that has text in it, to make the button turn from black to white and the text from white black at the same time. Instead of two separate elements. How should I do this?

Thanks!

#signUpBox {
    width: 150px;
    height: 47px;
    border-style: solid;
    border-width: 1px;
    margin: auto;
    margin-top: 25px;
    border-radius: 2px;
}

#signUpBox:hover {
    background-color: #ffffff;
}

h3 {
    text-align: center;
    margin-top: -35px;
    letter-spacing: 1px;
    font-size: 17px;
}
1
  • ...in five minutes you got 5 near identical answers... seems like you know what to do! :-) Commented Jan 24, 2014 at 4:55

5 Answers 5

5

I'm not sure how you have the code set up but this would work on a div with an onclick function attached as a button:

#signUpBox {
    width: 150px;
    height: 47px;
    border: solid 1px #000;
    margin: auto;
    margin-top: 25px;
    border-radius: 2px;
    color:#000;
    background:#fff;

}

#signUpBox:hover {
    background: #000;
    color:#fff;
}

HTML:

<div id="signUpBox">This is a test</div>

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

The div was the problem! Thanks! I'll answer this up in 6 minutes. I have to wait.
2
#signUpBox:hover {
    background-color: #ffffff;
    color:#000000;
}

Comments

2

you can do

#signUpBox:hover h3 {
  color: #000;
}

JSFIDDLE

Comments

2

change text color using color property on hover.

#signUpBox:hover {
    background-color: black;
    color: white;
}

Here is a demo.

2 Comments

color is to be made black else nothing will be visible.
@Joseph: see my demo fiddle.
1
#signUpBox {
    width: 150px;
    height: 47px;
    border-style: solid;
    border-width: 1px;
    margin: auto;
    margin-top: 25px;
    border-radius: 2px;
    background: #000000;
    color: #FFFFFF;
}

#signUpBox:hover {
    background: #ffffff;
    color: #000000;
    cursor: pointer;
}

Fiddle

Comments

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.