3

I am trying to do a really simple button using a div. Everything's fine, except that when the mouse cursor goes over the button, the text is supposed to turn black, and the background-color white...But currently, I have to put the mouse cursor over the text to see it turn black.

Here's my CSS code :

.pledges_boutons {
    width: 157px;
    color: #fff;
    font-family: "Arial Black", Gadget, sans-serif;
    font-size: 11px;
    height: 18px;
    text-align: center;
    margin-right: 10px;
    margin-left: 10px;
    margin-top: 5px;
    margin-bottom: 5px;
    text-decoration: none;
    display: block;
    background-color: #868686;
    }

and Hover :

.pledges_boutons:hover {
    color: #000;
    cursor: pointer;
    background-color: #fff;
}​

HTML:

<div class="pledges_boutons">
   <a href="http://www.google.com">Click here</a>
</div>​

Here's my fiddle

Thank you!

1
  • Please include your HTML in the question. Do not rely on jsFiddle demo for that. Edited. Commented Sep 28, 2012 at 17:33

4 Answers 4

8

Replace:

.pledges_boutons:hover {

With:

.pledges_boutons:hover, .pledges_boutons:hover a {

That will do the trick ;-)

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

Comments

3

There are a variety of ways to handle this, but essentially you need to provide a specific enough selector to override the style of the anchor when the parent is hovered.

Example: http://jsfiddle.net/6JCWn/1/

.pledges_boutons:hover a {
    color: #000;
}

Comments

1

It's because you are specifically styling the link to be white:

.pledges_boutons a:link {
    text-decoration:none;
    color:#fff;
}

The link is styled white using a selector that is more specific than:

.pledges_boutons:hover {
    color: #000;
    cursor: pointer;
    background-color: #fff;
}​

So what you want to do is change it to

.pledges_boutons:hover,
.pledges_boutons:hover a {
    color: #000;
    cursor: pointer;
    background-color: #fff;
}​

Once you do that, you can remove the rule directly above it, since it will be made redundant:

.pledges_boutons a:hover {
    color:#000;
    background-color:white;
}

Comments

-1

ctrl+F5 clears the browser page cache; the browser caches css files.

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.