The jQuery slideToggle animation causes navigation elements to shift unexpectedly

Hey there! I've been working on creating a drop-down menu using jQuery and I've encountered an issue. When I click on a navigation element, the other elements seem to drop about 20px. Any idea what might be causing this? Your help would be greatly appreciated. Thanks in advance!

Below is my code snippet or you can check out the jsFiddle for reference:

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;
}

Answer №1

Your CSS code needs some adjustments, try this instead:

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

Click here for the updated fiddle.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with sending POST data to server while trying to save to a JSON file using ajax and php

I attempted to follow the instructions from various stackoverflow posts, but it seems that my server is not acknowledging any incoming requests. I am certain that the client is sending the request because it can be seen in the Firefox debugger tool. Below ...

Submitting data twice through AJAX POST requests

Using a PHP file called via AJAX to insert data into MySQL. Prior to the insert statement, the PHP code runs a select query to check for duplicate records and then proceeds with the insert statement. Problem: When calling the PHP file from AJAX, it gets ...

Border extends across two separate rows

Let me illustrate my issue with a specific example where I am utilizing a single column with a rowspan: <table border="1" style="width:300px"> <tr> <td rowspan="2">Family</td> <td id="jill">Jill</td> <td>Smi ...

What is the best way to design a grid consisting of 14 divs that span the entire width of the browser screen, incorporating dividers to separate different groups, utilizing a combination of html,

I am interested in creating a layout with two rows of divs that span the entire width of the screen, with a total of 14 divs in each row. These divs are fixed in size and grouped by color, with dividers separating each color group. I am hoping to achieve ...

Is it possible to revert an image back to its original state after it has been altered on hover

I am currently experimenting with jQuery to create an image hover effect where hovering over one image changes the other. I've managed to accomplish that part successfully. However, I'm struggling with how to make the original image revert back w ...

Design elements - Responsive vertical images

I am facing an issue with resizing the slider I have on my website. Currently, it is set at 1200 x 400 pixels, and while the width adjusts correctly when the page is resized, the height remains fixed at 400px. I would like the height to resize proportional ...

Despite including jQuery, the error message 'JQ is not defined' is still appearing

Alright, so an individual over at is uploading content to The upload.cgi script responds with: <script language="javascript" type="text/javascript" src="http://upload.foobar.com/jquery-1.3.2.min.js"> </script> <script language="javascript ...

Deleting a division with the help of media queries

As a challenge, I am attempting to eliminate the .navbar-brand>img element once the screen size exceeds 768px by using media queries. Unfortunately, my efforts have not been successful so far. Although the styling applied to the img is successfully remo ...

Adjust the height of the page to fit the available screen space on mobile devices

Seeking a solution to ensure my web app fills the entire height of the device. Currently utilizing 100vh on the body tag, however, Safari tab on iOS adds an additional height which causes users to have to scroll down to view the full page. Any suggestions ...

Beginner: Interested in creating a web application with HTML, CSS, AngularJS, NodeJS, and MySQL?

After extensive searching on the internet, I have yet to come across a definitive answer. I am in the early stages of developing a web application and want to ensure that I am using the correct languages before diving too deep into it. Currently, my plan ...

What is the best method for customizing the color of angularjs spinners?

As I delve into developing an AngularJS application, my focus has been on seamlessly integrating an AngularJS spinner. Taking it a step further, I managed to tailor some of the spin-kit CSS properties to customize the appearance and behavior of the spinn ...

Dividing a select option

Looking to transform a single select element into multiple select elements using the separator "/" Here is an example of the original code: <select> <option value="1234">Type 1 / Black</option> <option value="5678">Type 2 / White& ...

Acquiring HTML form data using JavaScript

Although it may seem trivial, I'm facing a challenge. I have an HTML form that is dynamically generated by JavaScript and populated with initial data fetched from the server. The form is displayed correctly with the pre-filled data. My goal is to allo ...

Using JQUERY to create a dropdown menu that dynamically changes based on the date field

I am currently working on a JQUERY project and facing a challenging situation. I usually know how to create dropdown menus that depend on one another, but this time I need a dropdown menu that displays age ranges based on the date entered in the birth-date ...

The security protocols prevent me from placing calls to the Steam API site from my own website

I am venturing into the creation of a web application that uses steam web APIs and I find myself at a loss on how to kickstart this project. This question perfectly encapsulates my struggles, particularly in establishing endpoints and resolving the issue. ...

Transmit data from a form row to an external PHP script

I'm facing an issue that I need help resolving. My challenge is to transfer data from a form ROW to a php file. Below is the initial PHP code (embedded within an echo statement where values are fetched from a MySQLi query): <form id=\"comed ...

Modify path and refresh display upon ajax call to node server

Recently, I made the decision to utilize a Node server as a proxy for making API calls to third-party public APIs from my front end. After successfully sending a request to my Node endpoint and then to the third-party API, I received the expected response. ...

preserving the status of checkboxes based on an array of binary values

I am trying to figure out how to restore the state of checkboxes in an ORACLE APEX tabular form. The selection is made in the first column using the APEX row selector f01. After saving the checkbox state in a collection and then transferring it to an arra ...

Tips for choosing an option from a dropdown menu and triggering the onchange event using Jquery

I'm facing a challenge in selecting dropdown options dynamically based on data received from a social networking plugin. I also need to trigger an onchange event to populate successive dropdown menus. The data I am working with includes country, stat ...

Assistance required for locating elements in Selenium using Css Selector

Hi there, I'm not really a developer. I've got two checkboxes in my table without any IDs. Usually, I can easily work with Selenium when elements have IDs, but in this case, the table was generated using jquery datatables and no automatic ID ass ...