Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS change background color on hover

Tags:

css

Why is this not working?

            <div class="homePrizes">
                <div class="homeCredit">
                    1250 Points
                </div>
                <div class="homePrize">
                    Prize1
                </div>
            </div>

CSS:

.homePrizes {
    clear:both;
    width:100%;
    line-height:30px;
}

.homeCredit {
    font-size:14px;
    color:#F90;
    font-weight:bold;
    float:left;
}

.homePrize {
    font-size:14px;
    color:#000;
    float:right;
}

.homePrizes:hover {
    background-color:#FC6;
}

Thanks!

like image 850
Or Weinberger Avatar asked May 10 '26 05:05

Or Weinberger


2 Answers

Since .homePrizes has no content that isn't floating, doesn't have an explicit height, and doesn't apply any of the techniques for containing floats:

The container has a height of 0. As a result, there is no area for the pointer to hover over, and no visible space to have a background colour.

Change to:

.homePrizes {
    clear:both;
    width:100%;
    line-height:30px;
    overflow: hidden;
}

That said, since it is non-interactive, adding a hover effect would send the wrong signals the user. That sort of colour change shouts click me at the user.

like image 52
Quentin Avatar answered May 12 '26 01:05

Quentin


Try this:

.homePrizes {
    clear:both;
    width:100%;
    line-height:30px;
    overflow:hidden;
}

You need to add overflow:hidden to the parent div to expand its height and cover the children divs

like image 36
CodeOverload Avatar answered May 12 '26 02:05

CodeOverload



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!