2

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!

1
  • It is because of the floats, .homePrizes does not take up any space. You have to manually set a height for .homePrizes or align it differently. Commented Feb 20, 2011 at 15:58

4 Answers 4

9

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.

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

Comments

2

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

Comments

1

Add overflow:auto; to .homePrizes will work.

Reason: The child of .homeprizes are all float, that leads to the browser consider that to be 0 height element. Adding overflow:auto will fix it.

Comments

0

All you need is a quick edit to:

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

Good luck!

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.