user0129e021939232
user0129e021939232

Reputation: 6355

jQuery slideToggle moves navigation elements out of place

Hi I trying to create a drop down menu using jQuery, I'm using the slideToggle function in order to close the previous menu on the next click. However when I click a navigation element the other elements seem to drop about 20px.

I'm not 100% sure as to why this is occurring, would appreciate if somebody could tell me where I've gone wrong. Thanks in advance.

My code is below or view a jsFiddle

js/js.js

$('.nav_parent h5').click(function () {
  $(this).next('.nav_child').slideToggle();
   $(this).parent().siblings().children().next().slideUp();
    return false;
});

index.html

<div class="container">
    <ul id="header_nav">
        <li class="nav_parent">
            <h5>Reports</h5>

            <ul class="nav_child">
                <li><a href="#" class="mnavlink">Download CSV</a>
                </li>
            </ul>
        </li>
        <li class="nav_parent">
            <h5>Build</h5>

            <ul class="nav_child">
                <li><a href="#" class="mnavlink">Build new site</a>
                </li>
            </ul>
        </li>
        <li class="nav_parent">
            <h5>Subscriptions</h5>

            <ul class="nav_child">
                <li><a href="#" class="mnavlink">E-Briefings</a>
                </li>
            </ul>
        </li>
        <li class="nav_parent">
            <h5>Media Store</h5>

            <ul class="nav_child">
                <li><a href="#" class="mnavlink">Image Store</a>
                </li>
            </ul>
        </li>
    </ul>
</div>

css/style.css

.nav_parent {
    display:inline-block;
    width:24%;
    background:#FCCC5F;
}
.nav_parent h5:hover {
    background:#FCE49D;
}
.nav_child {
    display:none;
}
.nav_child li {
    line-height:30px;
}
.nav_child li:hover {
    background:#FCE49D;
}

Upvotes: 0

Views: 576

Answers (1)

gorgi93
gorgi93

Reputation: 2535

You have problem in your css. Change to:

.nav_parent {
    display:block;
    float: left;
    width:24%;  
    background:#FCCC5F;
}

http://jsfiddle.net/uCaQ2/ fiddle

Upvotes: 1

Related Questions