Issue with functionality of inline list menu

Having trouble with a JQ drop down menu and suspect it's an HTML/CSS issue. Spent hours tweaking it, but still not working as expected. Looking to understand the correct approach rather than just getting it to function. The slidetoggle feature is messing up the spacing and causing titles to shift when the menu expands. Setting heights and widths for space creates issues with untoggled titles being pushed downward.

The "visible" attribute allows me to toggle visibility for admins only.

Current code snippet:

<nav>
   <ul>
      <li style="display: inline;"><a href="Loggedin/Search.aspx" class="NavTitle ntAlter">Home</a>
      </li>
      <li style="display: inline;"><a href="Support.aspx" class="NavTitle ntAlter">Support</a>
      </li>
      <li runat="server" id="NavTitle1_wrap" visible="false" class="NavTitle" style="display: inline-block;">
         <span id="NavTitle1"> Items </span>
         <ul style="list-style-type: none;">
            <li><a style="display: none;" class="subMenu1">Add</a></li>
            <li><a style="display: none;" class="subMenu1">Approve</a></li>
            <li><a style="display: none;" class="subMenu1">Update</a></li>
            <li><a style="display: none;" class="subMenu1">Delete</a></li>
         </ul>
      </li>
      <li runat="server" id="NavTitle2_wrap" visible="false" class="NavTitle" style="display: inline-block;">
         <span id="NavTitle2"> Contacts</span>
         <ul style="list-style-type: none;">
            <li><a style="display: none;" class="subMenu2">Add</a></li>
            <li><a style="display: none;" class="subMenu2">Approve</a></li>
            <li><a style="display: none;" class="subMenu2">Update</a></li>
            <li><a style="display: none;" class="subMenu2">Delete</a></li>
         </ul>
      </li>
   </ul>
</nav>

Script handling the hover effect:

<script type="text/javascript">
    $('#NavTitle1').hover(function () {
        $('.subMenu1').stop(true, true).slideToggle('medium');
    });

    $('#NavTitle2').hover(function () {
        $('.subMenu2').stop(true, true).slideToggle('medium');
    });
</script>

Answer №1

If you're looking to improve your website's navigation, consider exploring nested lists. There are plenty of resources available on this topic, such as the article on A List Apart: Suckerfish Dropdowns that I found useful.

To see an example in action, check out this demo: http://jsfiddle.net/pHqKC/

<nav>
   <ul>
      <li><a href="Loggedin/Search.aspx" class="NavTitle ntAlter">Home</a>
      </li>
      <li><a href="Support.aspx" class="NavTitle ntAlter">Support</a>
      </li>
      <li runat="server" id="NavTitle1_wrap" visible="false" class="NavTitle">
         <span id="NavTitle1" class="menu"> Items 
             <ul class="submenu" style="list-style-type: none;">
                <li><a>Add</a></li>
                <li><a>Approve</a></li>
                <li><a>Update</a></li>
                <li><a>Delete</a></li>
             </ul>
         </span>
      </li>
      <li runat="server" id="NavTitle2_wrap" visible="false" class="NavTitle" style="display: inline-block;">
         <span id="NavTitle2" class="menu"> Contacts
             <ul class="submenu" style="list-style-type: none;">
                <li><a>Add</a></li>
                <li><a>Approve</a></li>
                <li><a>Update</a></li>
                <li><a>Delete</a></li>
             </ul>
         </span>
      </li>
   </ul>
</nav>​

When it comes to functionality, consider using JavaScript like this:

$(document).ready(function() {
    $('.menu').hover(
        function() {
            $(this).find('.submenu').show();
        },
        function() {
            $(this).find('.submenu').hide();
        }
    );
});​

Take a look at the CSS in the provided demo link for styling. Remember, starting simple is key before diving into more complex features. Good luck!

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

Perfect CSS Menu Hover Effect

I created my own navigation menu, and I'm struggling with one thing... How do I change the A tag color to white when hovering over the ul id "navitemul"? I've tried #lovedating#navitemul:hover #lovedating a {color:white} and other methods, but no ...

Smoothly automate horizontal scrolling using JavaScript

My programming journey involved creating a code snippet that automatically scrolls paragraphs horizontally, giving it the appearance of "Breaking News" updates on popular websites. The Javascript script I implemented performs automatic scrolling, but once ...

Lacking HTML5 support, your current location cannot be accessed on Google Maps

I have implemented google maps on my basic HTML website. Currently, I am able to center the map based on the user's current location using HTML5, however this requires obtaining permission from the user. Interestingly, when I visit maps.google.com, th ...

Cease all playback of audio immediately

My goal is to ensure that any audio that has been played previously stops before a new audio clip starts playing. This will prevent overlapping clips on elements that may trigger the audio file multiple times. I have attempted to pause and reset the curre ...

Recreate a null reference exception in a textbox following the action of clicking the Add button

How can I intentionally trigger a NullReferenceException in a textbox by changing its ID after clicking the Add button on the page? I have attempted to modify the textbox ID using developer tools before clicking the Add button, but the error is not thrown ...

The Laravel 5.4 Resource is encountering an Error 405, indicating that the PUT Method is not allowed when using

In my routes.php file: Route::resource('/users','UserController'); For ajax requests in ajax.js file: $.ajax({ url: "/users", type:'POST', data:$('.edit-user-for ...

Error: Unable to retrieve data through Ajax request

$(document).ready(function(){ /* Fetching Data from TTC for Union Station */ $.getJSON("http://myttc.ca/Union_station.json?callback=?", function(data){ if (routes.length > 0) { // Display the stop details with departur ...

Using Jinja2 to iterate through a dictionary while having the ability to choose which key-value pair to access

I'm attempting to generate an HTML table from data received on the web as a dictionary app.py: client = boto3.client('ec2') vpc_ids = client.describe_vpcs() for i in vpc_ids.get('Vpcs'): for tag in i.get('Tags'): ...

Interactive loading of datalist choices using AJAX in the Firefox browser

I have recently decided to replace the Jquery UI autocomplete function on my website with HTML5 datalists that load dynamic options. After researching this topic extensively, I came across various answers on Stack Overflow, such as How do you refresh an HT ...

Ways to avoid scrolling on a fixed element

Here is the HTML setup I have... body .top .content The issue I am facing is that when scrolling reaches the end of the ul in the .top element, the background starts to scroll. This can be quite disorienting and makes the site slow on tablets. Even ...

Having trouble getting FancyBox to function properly

Initially, fancybox was functioning properly. However, upon expansion of the site's content, it ceased to work and I am baffled as to where I made a mistake. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquer ...

Is there a way to update the options value using AngularJS?

One common issue that many people (myself included) are facing is with the ng-options directive in AngularJS when populating a <select> tag. Setting the value for an option seems to be unclear based on the documentation. For example, using ng-option ...

Filtering out section boxes does not eliminate empty spaces

Link to Fiddle I've run into a bit of a roadblock while trying to filter my section box for a project I'm currently working on. The issue I'm facing is that instead of collapsing the first section box to display only the filtered options, i ...

Tips for preventing the repeated loading of external libraries: Leveraging npm packages, using browserify, and strategically implementing script tags

I have developed a single-page web app using jQuery along with another library and a bundle.js created with npm and browserify. The bundle.js also relies on the same libraries. My architecture works like this: On the HTML page, I load certain functiona ...

What is the best way to eliminate the space between two buttons in a table row or "column"?

Below is the code snippet that I am working with. I am trying to figure out a way to eliminate the space between the buttons both horizontally and vertically. Can someone guide me on how to achieve this? <%@page contentType="text/html" pageEncodin ...

Adjust the text size in a collapsible tree based on the number of expanded components inside the container

Hi there, I'm currently developing a code for an expandable/collapsible tree using checkboxes. I have successfully implemented the basic functionality, but I have a specific requirement. I want the text size to decrease as the tree expands to prevent ...

SignalR's postback interrupts the functionality of jQuery actions

On my screen, I have a widget that updates data and changes its class based on server-side interactions. It also responds to mouse clicks. To notify multiple clients of updates simultaneously, I'm using SignalR. The problem arises when I wrap everythi ...

Ways to identify the specific occurrence when the nth image is displayed within a div containing an image slider

I am working on an image carousel with unique elements for each slide: <div class="outer_wrapper_hide" id="outer_wrapperID"> <div class="inner_wrapper" id="inner_wrapperID"> <img id="slideimage1" class="slideimage" height="500" ...

Is it possible to change %20 in a URL to a hyphen?

Is there a way for my search form to display %20 in the URL when I fill the input field with spaces? For example: Basketball coach Current output: basketball%20coach Desired output: basketball-coach <form action="/tag/" id="form-hockey_v1" name=" ...

Guide on Updating the ColModel Dynamically in JAVASCRIPT/HTML using clearGridData, setGridParam, and reloadGrid Functions

I am trying to figure out how to dynamically change the colmodel of my grid using a function that is called by a SELECT. The reason for this is because my grid has different periods and needs to display either cost or tons based on user selection. Below i ...