Introducing a variety of sub-menu fonts within an elegantly designed jQuery vertical accordion menu

I am struggling to achieve different font sizes, colors, and weights for top and sub-menu level links in my simple jQuery vertical accordion. Despite changing the CSS, I can't seem to get it right. What am I missing? Is there an easy way to accomplish this?

HTML Code:

<script type="text/javascript">
 $(document).ready(function () {
    $('#nav > li > a').click(function(){
       if ($(this).attr('class') != 'active'){
          $('#nav li ul').slideUp();
          $(this).next().slideToggle();
          $('#nav li a').removeClass('active');
          $(this).addClass('active');
       }
    });
 });
</script>
<style type="text/css"></style>
</head>
<body>
  <ul id="nav">
    <li><a href="#">Item 1</a>
      <ul>
        <li><a href="#">Sub-Item 1 a</a></li>
        <li><a href="#">Sub-Item 1 b</a></li>
        <li><a href="#">Sub-Item 1 c</a></li>
      </ul>
    </li>
    <li><a href="#">Item 2</a>
      <ul>
        <li><a href="#">Sub-Item 2 a</a></li>
        <li><a href="#">Sub-Item 2 b</a></li>
      </ul>
    </li>
    <li><a href="#">Item 3</a>
      <ul>
        <li><a href="#">Sub-Item 3 a</a></li>
         <li><a href="#">Sub-Item 3 b</a></li>
        <li><a href="#">Sub-Item 3 c</a></li>
        <li><a href="#">Sub-Item 3 d</a></li>
      </ul>
    </li>
    <li><a href="#">Item 4</a>
      <ul>
        <li><a href="#">Sub-Item 4 a</a></li>
        <li><a href="#">Sub-Item 4 b</a></li>
        <li><a href="#">Sub-Item 4 c</a></li>
      </ul>
    </li>
  </ul>
</body>

Here is my CSS Code:

}
#nav {
float: left;
width: 155px;
border-top: 1px solid #999;
border-right: 1px solid #999;
border-left: 1px solid #999;
}
#nav li a {
display: block;
background: #ccc;
border-top: 1px solid #eee;
border-bottom: 1px solid #999;
text-decoration: none;
color: #000;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
padding-top: 2px;
padding-right: 3px;
padding-bottom: 4px;
padding-left: 3px;
}
#nav li a:hover, #nav li a.active {
background: #999;
color: #fff;

}
#nav li ul {
display: none; // used to hide sub-menus
}
#nav li ul li a {
background: #ececec;
border-bottom: 1px dotted #ccc;
padding-top: 2px;
padding-right: 3px;
padding-bottom: 4px;
padding-left: 3px;

}

Any guidance on this matter would be greatly appreciated!

Answer №1

Here is a snippet to style the submenus specifically:

ul#nav li ul li {
    /* apply custom styles to font and more */
}

Alternatively, you can target the 'a' tags within the submenus with this code:

ul#nav li ul li a {
    /* specify CSS properties for fonts and other styles */
}

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

A guide to implementing drag and drop functionality using JavaScript

I have developed a unique drag and drop application that features both a left and right panel. The issue I am facing is that when I drag the ball from the left panel to the right panel, it does get dragged successfully. However, the problem arises when the ...

Setting the background color in the navbar of a Laravel application

I'm having trouble changing the color of my navbar to blue in certain parts. I've tried using background: lightblue;, but for some reason, two sections remain white. How can I make them completely blue? (see screenshot below) Any help would be ap ...

Overflow: Truncating text with an ellipsis in the center

Seeking a CSS-only solution for adding an ellipsis in the middle of a string when it exceeds its container. I have tried splitting the container in half, trimming the first half with a wrapper on a whole letter and adding an ellipsis to the front of the s ...

DANGEROUS EVALUATION: Tips for Safe Replacement

Looking for a safer alternative to the code below which utilizes eval. The script creates pop-up windows based on different classes. /* exported popup_default , popup_help , popup_sitemap , popup_footerlinks */ var matchClass = ['popup_default' ...

Make the checkbox font-weight bold when it is checked

Attempting to apply custom CSS to enhance the appearance of checkboxes using input and label elements. The goal is to make the font-weight bold when a user clicks on the checkbox, and then revert it back to regular if clicked again. Currently stuck on this ...

Ensuring the successful execution of all AJAX calls (not just completion)

I've seen this question asked many times about how to trigger a function once all AJAX calls have finished. The typical solution involves using jquery.stop(). However, my situation is unique - I want to display a confirmation banner only after all AJA ...

jQuery has been utilized to clone a form, resulting in the fields becoming inactive

I have a basic form with some fields that are affected by the click event. In addition to this, I am duplicating the form and appending it (with the intention of renaming the fields, but I have not succeeded yet). The problem I am facing is that after cl ...

What is the best way to choose a particular radio button from a group of radio buttons using typescript?

Is there a way to automatically select a specific radio button when an item is chosen from a dropdown menu on the webpage using a TypeScript function that is triggered by the dropdown selection? ...

Having trouble receiving the response from PHP after making an AJAX request

Can you help me figure out why I'm not receiving any return value from the ajax data post? Take a look at my code and let me know where I might be going wrong. Here is a snippet of my jQuery code: $("#btnlogin").click(function(){ var email = $( ...

Ensure that this regular expression is able to accurately match all numbers, even those without decimal points

Seeking help to create a script that can extract the negative percentage value between two numbers. One of the numbers is dynamic and includes different currencies, decimals, etc., so I believe a regex is needed for this task. The current script works, but ...

Using jQuery to append text after multiple element values

I currently have price span tags displayed on my website: <div> <span class="priceTitle">10.00</span> </div> <div> <span class="priceTitle">15.00</span> </div> <div> <span class="priceTitle">20.0 ...

Retrieve the parent's current state by accessing it through a callback function in React

My callback function onRestore is only logging the history until the id of the clicked snapshot. Why is it showing incorrect state? I've exhausted all options, so any help would be appreciated. import React, { useState, useEffect, useRef } from "re ...

Using webapp2 to serve a stylesheet in a non-Google App Engine environment

After successfully deploying an app using webapp2/jinja2 and a Paste server, I encountered difficulties serving static stylesheets. I managed to access static files by following this method. Additionally, I implemented a StaticFileHandler that I discovere ...

Creating a Jquery Dialog in MVC 4 without redirecting to a new page

I have a page with 5-7 or more links, and I want to display the link's data in a dialog box. However, when clicking on a link, it opens the link in the window and also displays the data in the dialog box. Can you please advise on the correct way to di ...

Creating a responsive carousel that is not yet designed

As a beginner, I'm facing what seems like a simple problem that I just can't solve. Here is the HTML code I've written: <div class="discs container"> <ul> <li><div class="arrowleft"><a href="#" >< ...

Ensure the accordion is fully loaded before initializing by checking if it has been loaded before using the .html() method

One issue I am facing is that the accordion html is being injected onto a tag using .html() before the accordion initialization, resulting in the injected html appearing as plain html. Below is my script: $(function() { $( "#accordion1" ).accordion({ ...

AngularJS and the Angular UI Router were combined for the first time in

Hey everyone, I could really use some help as I'm just diving into the world of AngularJS. Can anyone guide me on how to tackle these pesky errors? Error: app.js:6 > Uncaught ReferenceError: angular is not defined Error: angular.min.js:6 > Unc ...

Tips on using JQuery to extract form field information from a drop-down menu, display it in a div, and then compare it with the subsequently

In my HTML file, I am using two dropdown lists and JQuery for validation. First, I need to save the selected items from both dropdown lists in a variable and then compare them with the next selection. If the data from both dropdown lists match, an alert m ...

Managing the vertical dimensions of a div

I've created a unique set of visually appealing cards that house meaningful messages within an infinite scrolling feed. The intended functionality is for the complete message to be displayed upon clicking a "more" button, as the messages are typically ...

identify when the bottom of a container is reached during scrolling through a window

On my website, I have a section with products displayed in the center of an HTML page. I am looking to implement an AJAX call that will load additional products when the user reaches the bottom of this product container by scrolling down. How can I detec ...