Drop-down Navigation in HTML and CSS is a popular way to create

My navigation menu is functioning well and has an appealing design.

The HTML structure for the menu is as follows:

<div id="menubar">
    <div id="welcome">
        <h1><a href="#">Cedars Hair <span>Academy</span></a></h1>
    </div><!--close welcome-->
    <div id="menu_items">
        <ul id="menu">
            <li class="current"><a href="index.html">Home</a></li>
            <li><a href="index.html">The Salon</a></li>
            <li><a href="index.html">Testimonials</a></li>
            <li><a href="index.html">Courses</a></li>
            <li><a href="index.html">The Staff</a></li>
            <li><a href="index.html">Contact Us</a></li>
        </ul>
    </div><!--close menu-->
</div><!--close menubar-->  

I am now looking to modify it to include a dropdown under 'The Salon' with an option for 'Hair Cut':

<li><a href="#">The Salon</a>
    <ul>
        <li><a href="#">Hair Cut</a></li>
    </ul>
</li>

While I know this can be achieved using CSS, my concern lies in the complexity due to existing CSS styles associated with the aforementioned divs (menubar, welcome, menu_items etc.). Could you suggest the simplest method to implement a dropdown menu?

Answer №1

A quick and easy method summarized:

https://jsfiddle.net/svArtist/2jd9uvx0/

  1. Conceal nested lists

  2. When hovering over list items, reveal the sub-lists

ul ul {
    display:none;
    display:absolute;
    bottom:-100%;
}
li{
    position:relative;
}
li:hover>ul {
    display:table;
}
<ul>
    <li><a href="#">The Salon</a>
        <ul>
            <li><a href="#">Hair Cut</a>
            </li>
        </ul>
    </li>
</ul>

Answer №3

Implemented the sub menu feature with the hover property on li elements.

You can view the demonstration on this code snippet - https://example.com/demo

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

When you hover over a Wordpress page, the entire text on the page will be underlined

Currently designing my own website using WordPress with the Elementor free plugin and Phlox theme. I've made some progress by completing a few sections which include text, buttons, and images. However, I'm encountering an issue where all the text ...

Hide dynamic jQuery UI tabs that are not selected

About My Project: Currently, I am developing a chat system that utilizes websockets. In order to enhance the user experience, I have integrated jQuery UI tabs for the design. These tabs will facilitate communication in various chatrooms and private setti ...

How can we arrange a two-dimensional array in descending order of string length using the first string in the sub-array as the basis for

If I have an array with elements like these: var array = [["This should be last", 1], ["This should be first I think", 1], ["This is the middle one", 1]]; The second value in each sub-array, which is always 1 in this case, doesn ...

Emphasizing hyperlinks according to the user's scrolling location

Currently, I am attempting to create a feature where links are highlighted when the user scrolls over the corresponding section on the page. However, there seems to be an issue with the functionality as Link 2 is highlighting instead of Link 1 as intende ...

Navigating with buttons in the Material UI Drawer

I have implemented a Material UI drawer with some modifications. The original code used buttons, but now I want to navigate to a new page when a button is clicked. For example, clicking on the 'INBOX' button should take me to a page '/new&ap ...

What is the most efficient way to query through a Firestore database containing 5,000 users?

We are currently facing a challenge with our staffing application, which is built using vuejs and a firestore database containing over 5,000 users. Our primary issue lies in the need for a more efficient layout that allows admins to search for users within ...

Having issues with triggering a function from child props in React

I've been working on firing a function from an onClick event in a child component. getTotalOfItems = () => { console.log('anything at all?') if (this.props.cart === undefined || this.props.cart.length == 0) { return 0 } else { ...

Firebase Hosting is not compatible with Express session

After setting up my code as shown below, I noticed that sessions are being persisted and the page is able to count the number of visits. app.set('trust proxy', true) // The documentation specifies '1' instead of 'true' app.u ...

Adding Gridster to a WordPress theme

I am having an issue with implementing Gridster into my WordPress plugin. Despite correctly loading the necessary files from the folder, it does not seem to work. function add_my_stylesheet() { wp_enqueue_style( 'myCSS', plugins_url( ' ...

Accessing the parent scope from a directive within a nested ng-repeat in AngularJs

Seeking guidance on accessing the parent scope within a directive nested in an ng-repeat. Here is an example: <div ng-app="myApp" ng-controller="myCtrl"> <div ng-repeat="section in sections"> {{section.Name}} <div ng-rep ...

Discover the secrets of accessing two distinct objects returned by a single REST URL with Backbone

I am working with a REST URL that looks like this: /users/<user_id>/entities This URL returns data containing 2 objects as follows: { "players": { "test_player2": { "_id": "test_player2", "user": "f07590 ...

Is it possible to leverage Create-React-App's npm start in conjunction with Node.js?

I've recently started diving into React and node.js. My goal is to have a node.js server that can serve up React.js pages/views. After running 'create-react-app' and then using 'npm start', I'm not sure if I also need to man ...

Retrieving data from the firebase database by filtering based on the child's specific value

Looking at the firebase database, I can see that only the 'name' field is available. Now, I am trying to retrieve the 'quantity' value associated with that specific 'name'. Can someone provide me with a sample firebase query i ...

Creating unique styles with styled components without the use of selectors

Is it possible to achieve contextual styling without using CSS selectors? For example: <Button primary> <Text>BUTTON</Text> // if the button is primary then have 20px padding else 0 <Icon/> // if the button is primary then ...

Quick method for handling arrays to generate waveforms

I'm currently working on optimizing the code for my web application. While it functions, the performance is a bit slow and I am looking to make improvements: The main concepts behind the code are: The function retrieves the current buffer and conve ...

Leverage the power of jQuery's .filter() method to pinpoint and target specific text

HTML: <p class="greeting"> hello, my name is kevin. what's yours? </p> jQuery: $("p.greeting").filter(function (){ return $this.text() === "my name is"; }).css("background", "green"); I am attempting to find and highlight the phra ...

React Redux Loading progress bar for seamless navigation within React Router

Currently, I am working on adding a loading bar similar to the one used by Github. My goal is to have it start loading when a user clicks on another page and finish once the page has fully loaded. In order to achieve this, I am utilizing material-ui and t ...

Eliminate all key-value pairs from an array of objects except for the specified key-value pair

I've got an array filled with objects const myArr = [ {k1: 1, k2: 1, k3: 3, k4: 4}, {k1: 1, k2: 2, k3: 3, k4: 4}, {k1: 1, k2: 2, k3: 3, k4: 4}, {k1: 1, k2: 2, k3: 3, k4: 4} ] I'm attempting to filter these objects, although I don&apos ...

initial render results in undefined data

function Story() { let { id } = useParams(); const pin = useSelector(state => state.pins.pin); const dispatch = useDispatch(); const userid = 2 useEffect(() => { dispatch(getPin(id)); }, [dispatch, id]); return ( <div classN ...

What is the best approach to display data in React fetched from an API request? If this is not the right method, what changes should be made to the JSX rendering to convert

As I begin my journey with React, I find myself questioning the best practices for displaying data. Should I always break down components into smaller ones rather than having one large component render everything? It seems like a good practice, but I' ...