Show all menu items in a single row, allowing for customization of the line height

My goal is to showcase all of my menu items in a line while keeping the sub-menus hidden until their parent is hovered over. I achieved the inline display using 'display: inline', but encountered an issue where the sub-menu disappears when the cursor is between two item lines due to uncontrollable line height and cursor positioning outside the main li element. I've considered using the 'display: flex' property, but struggled to make it work. Any ideas or suggestions?

https://i.sstatic.net/gB44l.png

https://i.sstatic.net/824Kr.png

Here's the HTML code:

        <div id="menu-container">
<div class="menu-menu-container"><ul id="menu-menu" class="menu"><li id="menu-item-22" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-22"><a href="http://localhost:8888/le-projet/">Le projet</a>
<ul class="sub-menu">
    <li id="menu-item-23" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-23"><a href="#presentation">Présentation</a></li>
    <li id="menu-item-24" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-24"><a href="#projet">Le projet</a></li>
    <li id="menu-item-25" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-25"><a href="#site">Le site</a></li>
    <li id="menu-item-26" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-26"><a href="#equipe">L'équipe</a></li>
    <li id="menu-item-27" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-27"><a href="#partenaires">Les partenaires</a></li>
</ul>
</li>
<li id="menu-item-21" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-21"><a href="http://localhost:8888/les-collections/">Les collections</a>
<ul class="sub-menu">
    <li id="menu-item-28" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-28"><a href="#collections-frac">Les collections</a></li>
    <li id="menu-item-30" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-30"><a href="#dernieres-acquisitions">Les acquisitions</a></li>
    <li id="menu-item-31" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-31"><a href="#carte">La carte de diffusion</a></li>
    <li id="menu-item-32" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-32"><a href="#modalites">Les modalités</a></li>
</ul>
</li>
</ul>
</div>

And here's the CSS styling used:

#menu-container { width: 100%; padding: 0px; }

.menu { font-size: 35px; line-height: 55px; }

.menu a { color: black; }

.menu-item-has-children a { font-weight: bold; }

.menu-item-has-children ul a { font-weight: normal; }

.menu li li { margin-right: 10px; }

.menu li:hover .sub-menu { opacity: 1; }

.menu .sub-menu { margin-left: 10px; opacity: 0; }

.menu li, .menu ul { display: inline; }

If you'd like to view a working example, check out this jsfiddle link: https://jsfiddle.net/vcs3fyxh/

Answer №1

If that's the situation, you have the option to adjust how the sub-menu items are displayed:

ul.sub-menu li{
  display: inline-block;  
}

It seems like this resolves the problem unless a different issue pops up :p

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

Can object methods be called using inline event attributes in an HTML tag?

Exploring the depths of core JavaScript has been my latest obsession. It's fascinating how we can easily trigger functions within the global context using events like this. HTML <span class="name" onclick="clicked()">Name</span> JavaSc ...

I encountered a roadblock with the npx create-react-app command in my-app, as it was getting stuck at the

Here is the command I used to install React I've been wanting to learn React, so I attempted to install it using the command npx create-react-app my-app. The installation process began, installed some files, and then displayed a "done" message in 98 ...

Limiting the types of files a user can access through a web browser

Hey there! I have a unique question that sets it apart from others, as it involves restricting file types for users with a browser popup. My goal is to prevent users from selecting certain file types before they choose a file. I've come across some s ...

Press the designated button located within a table's td element to retrieve the values of adjacent td elements

I need to implement a functionality where clicking a button within a <td> element will retrieve the values of other <td> elements within the same row (<tr>). Here is the current implementation: $(document).ready(function(){ ...

Eliminate the initial padding in an everlasting horizontal CSS animation

Is there a way to start an infinite horizontal animation inside the screen instead of outside and then bring it in? I have successfully implemented the animation, but it currently starts off-screen. .marquee { margin: 0 auto; white-space: nowrap ...

Creating a fully responsive HTML page with a fullscreen image background

Seeking help from someone who can assist me. I have a challenge in creating a webpage with a background image that fills its <div>. Here is the code I used: <style type="text/css> .myclassdiv { background-image:url('IMAGEURL') ...

The issue arises when trying to set the height of the modal body correctly while using ng-bootstrap to open the modal as a separate component

There seems to be an issue with the height not being properly added in the modal body when the modal is opened as a separate component using ng-bootstrap. The problem can be seen in the following link: https://i.sstatic.net/natkn.png https://stackblitz.co ...

Utilizing ASCII art in React: A guide to incorporating textual designs into your

I'm having trouble displaying ASCII images correctly on my React app. I've tried various methods, but nothing seems to maintain the form when rendered in the browser. <Grid container id="terminal_banner"> <Grid item ...

The express-handlebars module is having trouble parsing HTML within the main layout file in an Express.js application

Hello, I am facing an issue with handlebars as it is not reading the HTML in my file. Here is a screenshot highlighting the problem along with the provided code. The folder structure is as follows: views layouts main-layout.hbs home.hbs https://i ...

CSS not affecting DIV height properly

Alright, so I'm facing a little issue with a div that's nested within a form. The form has been set to a minimum height of 100%, however, the child div doesn't seem to stretch even after adjusting the height or min-height properties to 100%. ...

"Exploring the World of Mobile Development and Screen Size

Currently, I am in the process of creating a basic mobile website that can be accessed through a QR code leading to the page linked below. However, I have encountered an issue where viewing it on my Android or Apple phone results in excess width. Any advic ...

Unable to fix the unhandled reference error

https://i.sstatic.net/cJdyl.jpgI'm currently working on a website design and running into an issue with the 'draw_images' function being referenced as undefined, even though I have already defined it. I suspect this error may be due to scopi ...

Go to the identical page with a message embedded in it

Creating a login page using JSP involves an index.jsp file which contains the form and javascript scriplets. The connectivity to an Oracle database and validation of username and password are handled in check1.jsp. The problem arises after entering the us ...

Resource loading error: The server returned a 404 (Not Found) status code, as shown in the console

Click here I have a simple file structure where index.html, script.js, and login.js are all in the same root folder without any subfolders. The issue I'm facing is that although the connection to the database works fine, there seems to be a problem wi ...

Tabbable bootstrap with dropdown functionality

I am currently in the process of integrating Bootstrap tabs and dropdown menus using version 2.3.4 <div class="container"> <div class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container-fluid"> ...

Rotating an object with the mouse in three.js without relying on the camera movements

I am working on a project where I need to create multiple objects and rotate each of them individually using the mouse. While I have been able to select an object with the mouse, I am facing challenges when it comes to rotating them with the mouse. Cur ...

Positioning the tooltip to the left side

I need help with customizing a tooltip in my code. I want the tooltip text to be displayed on the next line and positioned on the left side. You can view a demo here. <div id="demo"> <p title="The tooltip text I want this in next line"> Too ...

Field cannot be submitted without the required input after an Ajax request

I want to ensure that all my text/email input forms require a submission before you can "Submit" the email. Unfortunately, when using Ajax to prevent the page from refreshing after pressing the button, the required attribute does not function properly. T ...

Switching from a vertical to horizontal tab layout in Angular 4 Material 2 using MD-Gridlist

I'm currently trying to modify the tabbing functionality within an MD-Gridlist so that it tabs horizontally instead of vertically. I've experimented with tab indexes but haven't had any success. My goal is to enable horizontal tabbing throug ...

Interactive Thumbnail Selection for HTML5 Video

Having trouble with creating thumbnails? I managed to solve the cross-domain issue using an html2canvas PHP proxy. No error messages in the Console, but the thumbnails are unfortunately not showing up - they appear transparent or white. Here is a snippet ...