0

What I want is I have an invisible div somewhere, and then when you hover over it it appears (maybe with a transition, not necessary.). So I've tried the following:

-- CSS code

div.appearingBox {
display: none;
width: 100px;
height: 100px;
}

div.appearingBox:hover {
display: block;
width: 100px;
height: 100px;
background-color: rgb(0,0,0);
border: 1px solid rgb(0,0,255);
}

-- HTML code (Added)

<html>
    <body>
        <div class="appearingBox">
        </div>
    </body>
</html>

This doesn't work... Please help!

1

1 Answer 1

5

You'll need a wrapping div. Because it's not visible, it can't respond to :hover. Note that the :hover is on the wrapper instead of the element itself. That is because the wrapper is "visible" but transparent.

http://jsfiddle.net/Cs87c/1/

HTML:

<div class="appearingBox">
    <div>Hidden</div>
</div>

CSS:

.appearingBox div {
    visibility: hidden;
    width: 100px;
    height: 100px;
}

.appearingBox:hover div {
    visibility: visible;
    width: 100px;
    height: 100px;
    background-color: rgb(0,0,0);
    border: 1px solid rgb(0,0,255);
}

(Edited to a cleaner version)

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

3 Comments

I agree, nice job on figuring this out.
I have updated Davy8's answer to add a transition... jsfiddle.net/Cs87c/2
@superUntitled Such a simple thing but makes it so much more elegant i have been using this on all my hovers for a while now and wish more dev would do the same. great addition :)

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.