0

I am using a list for the nav for the nav of my website and when a user hovers over certain list items a dropdown appears with extra navigation options. In my case when a user hovers over the "Brands" item then a dropwdown appears with all the different brands. At the moment the dropdown appears instantly however I'd like it to appear in a motion as if it is sliding down rather than just appearing instantly. Is this possible with CSS or do I need some jQuery magic ?? Code:

HTML:

    <section id="nav">

        <div id="nav-wrapper">

            <ul id="nav-list">

                <li id="nav-home"><a href="">Home</a>
                </li>
                <li id="nav-brands"><a href="">Brands</a>
                    <ul id="brands-list">
                        <li><a href="">Brand 01</a>
                        </li>
                        <li><a href="">Brand 02</a>
                        </li>
                        <li><a href="">Brand 03</a>
                        </li>
                        <li><a href="">Brand 04</a>
                        </li>
                        <li><a href="">Brand 05</a>
                        </li>
                    </ul>
                </li>
                <li id="nav-about"><a href="">About Us</a>
                </li>
                <li id="nav-contact"><a href="">Contact Us</a>
                </li>

            </ul>

        </div>

    </section>

CSS :

#nav-brands { position:relative; }

#nav-list li:hover ul { display: block; opacity: 1; visibility: visible; background-color: #fff; }

#brands-list { padding: 10px 0px 0px 0px; position: absolute; top: 20px; left: -35px; width: 120px; box-shadow: none; display: none; opacity: 0;
               visibility: hidden; -webkit-transiton: opacity 0.2s; -moz-transition: opacity 0.2s; -ms-transition: opacity 0.2s;
               -o-transition: opacity 0.2s; -transition: opacity 0.2s; border:thin solid #000000; border-radius:0px 0px 5px 5px;
               border-top:0px;
}

#brands-list li { display: block; margin:0px 0px 5px 0px; padding:0px 0px 5px 0px; text-align:center; border-bottom:thin solid #CECECE;

}

#brands-list li:hover {}

#brands-list li:last-child { border-bottom:0px; }

3 Answers 3

2

No Jquery magic.

A css approach would be to wrap your sublist within a div. Use that div to set the submenu position, and then use an overflow / transition trick to give to the inner list the sliding effect you are looking for.

See it here: http://jsfiddle.net/vrGfc/

Also, remove the hover effect from the submenu itself. It will only need to be applied to the wrapper div.

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

Comments

2

See an example

http://jsfiddle.net/DHW9v/1/

You need set transition-timing-function

transition: opacity .8s ease-in-out;

2 Comments

Actually, he mentioned a "sliding down" effect.
I just edited his fiddle, he try bind transition effect on opacity.
0

There's no need for any jQuery or anything like that here - the css properties you're looking for are "transitions" - http://www.w3schools.com/css/css3_transitions.asp

3 Comments

So it would be something along the lines of :
#nav-list li:hover ul { -webkit-transformation: display 4s; }
webkit is only necessary for Safari 3.1 to 6.0. If you want to support safari, then you want {-webkit-transformation: display 4s; transition: display 4s;}

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.