CSS Dropdown Menu Malfunctioning

I recently created a navigation bar using some online tutorials, and everything seems to be working fine except for the drop-down menu. I've been struggling with it for hours and can't seem to find a solution. Any help would be greatly appreciated! I feel like I'm so close to getting it right but just can't figure it out. Thank you in advance for your assistance.

<style>

header { font-family: 'blades_gf_freeregular', Futura, Arial, sans-serif; }
nav { height: 41px; background: linear-gradient( #1e7995, #1c2c3f); }
nav ul { margin: 0; }
nav, ul.submenu { background: linear-gradient( #1e7995, #1c2c3f); border-radius: 5px; padding: 0; }
nav ul li { display: block; width: 150px; text-align: center; float: left; margin: 0; padding: 0; }
nav li:hover { background: rgba(0,0,0,0.4); }
nav a { color:#fff; text-decoration: none; display: block; padding: 10px; }
nav ul.submenu { background: rgba(0,0,0,0.8); position: relative; boredr-radius: 0 0 5px 5px; height: 0px; overflow: hidden; }
nav ul.submenu li { float: none; text-align: left; border-bottom: 1px solid rbga(0,0,0,0.3); }

nav ul li { transition: .3s all linear; }
nav ul li:hover ul.submenu { height: 126px; }

</style>


<header>
<p><img src="assets/images/header32.png" alt="before and after effects title image"/></p>
<nav role="navigation" aria-label="Main menu">

<ul role="menubar">
<li role="menuitem" tabindex="0"><a href="#">Home</a></li>
<li role="menuitem" aria-haspopup=true tabindex="0"><a href="#">Tutorials</a></li>

<ul class="submenu" role="menu" aria-hidden=true>

<li role="menuitem" tabindex="-1"><a href="pre-pro.html">Pre-Production</a></li>
<li role="menuitem" tabindex="-1"><a href="production.html">Production</a></li>
<li role="menuitem" tabindex="-1"><a href="post.html">Post</a></li>

</ul>
<li role="menuitem" tabindex="0"><a href="#">Films</a></li>
</ul>
</nav>
</header>

Answer №1

To properly structure your menu, ensure the sub menu ul is moved inside the menu li

<header>
<p><img src="assets/images/header32.png" alt="before and after effects title image"/></p>
<nav role="navigation" aria-label="Main menu">

<ul role="menubar">
<li role="menuitem" tabindex="0"><a href="#">Home</a></li>
<li role="menuitem" aria-haspopup=true tabindex="0"><a href="#">Tutorials</a>

<ul class="submenu" role="menu" aria-hidden=true>

<li role="menuitem" tabindex="-1"><a href="pre-pro.html">Pre-Production</a></li>
<li role="menuitem" tabindex="-1"><a href="production.html">Production</a></li>
<li role="menuitem" tabindex="-1"><a href="post.html">Post</a></li>

</ul>
  </li>
<li role="menuitem" tabindex="0"><a href="#">Films</a></li>
</ul>
</nav>
</header>

Check out the DEMO here

Answer №2

Your code prematurely closed the parent <li> element before adding the submenu.

Check out this JSFiddle link for reference.

<header>
<p><img src="assets/images/header32.png" alt="before and after effects title image"/></p>
<nav role="navigation" aria-label="Main menu">

<ul role="menubar">
<li role="menuitem" tabindex="0"><a href="#">Home</a></li>
<li role="menuitem" aria-haspopup=true tabindex="0"><a href="#">Tutorials</a>

<ul class="submenu" role="menu" aria-hidden=true>

<li role="menuitem" tabindex="-1"><a href="pre-pro.html">Pre-Production</a></li>
<li role="menuitem" tabindex="-1"><a href="production.html">Production</a></li>
<li role="menuitem" tabindex="-1"><a href="post.html">Post</a></li>

    </ul></li>
<li role="menuitem" tabindex="0"><a href="#">Films</a></li>
</ul>
</nav>
</header>

Make sure to correctly nest your elements and remember that a <ul> should only have <li> children, not another <ul>.

Answer №3

Almost there! Based on your CSS, the ul.submenu should be located within its corresponding <li> element. Simply move it inside the <li>. You can view the updated jsfiddle here:

http://jsfiddle.net/8WGKU/

Answer №4

Remember to place the submenu within the <li>

<li role="menuitem" aria-haspopup=true tabindex="0"><a href="#">Tutorials</a>           
    <ul class="submenu" role="menu" aria-hidden=true>
        <li role="menuitem" tabindex="-1"><a href="pre-pro.html">Pre-Production</a></li>
        <li role="menuitem" tabindex="-1"><a href="production.html">Production</a></li>
        <li role="menuitem" tabindex="-1"><a href="post.html">Post</a></li>
    </ul>
</li>

Access the Fiddle here.

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

Tips for aligning an icon vertically within a span tag

I have a span similar to this: <span class="indicator"></span> Sometimes this span contains numbers like: <span class="indicator"> <span>10</span> </span> Other times it may display Kendo-UI icons, such as: < ...

sending information through PHP and HTML

Trying to transfer data from a table search to another PHP page, here is the code: echo " 1<form action='adm_edit.php?product_code=$record[0]' method='POST'> 2<input type=submit value=Edit> 3</form> 4<form action= ...

Generating dynamic divs in parallel

Despite encountering numerous posts related to the issue at hand, none of them have solved my specific problem. I am aiming for 3 divs to display in each row, but the current code is causing each div to show up on a new line vertically: JQuery ...

Cursor or caret bleeding through overlay on Internet Explorer

Currently, I am working on a pre-existing website called www.shopthethirdfloor.com. When using Internet Explorer, if you navigate to the products menu, select the search box, and then scroll down so that the search field goes underneath the menu overlay ...

Using jQuery to Drag: Creating a draggable effect on a div element

I recently posted a question, but I feel like I need to rephrase it to make it more general. Basically, I have an element that can be moved around and resized using jQuery. I used CSS to attach another div to the right of this element. Initially, when you ...

Maximizing the width of navbar elements with Bootstrap 3

I am currently working on building a webpage with bootstrap3, but I have encountered an issue with the navigation bar. I would like the navigation links ("Web Design", "Development", "Photography", "Blog") to be evenly spaced out within the horizontal na ...

The Bing map control fails to adhere to the div element

After visiting , I successfully generated a map using the following HTML code: <div class="fluid-row" style="height:300px;"> <div class="span12"> <div id="prdmap" class="map"> </div> </div> Here is the accompanying J ...

Exploring Angular 7: Understanding the HTML5 Fullscreen API and Overcoming Errors

I am currently using Angular 7 and I am trying to implement a fullscreen button in my app. I have utilized the HTML5 Fullscreen API and created two functions for this purpose: openfullscreen() { // Trigger fullscreen console.log('gg'); ...

Opening a Material Dialog automatically scrolls the body to the top of the page

I'm currently using Material UI within a React application and I'm facing an issue where opening a dialog causes the body of my page to scroll to the top. This behavior also occurs when opening a Material Popover or a Material TextBox selector. D ...

What's the best way to customize the appearance of an OPTION field using inline text styling

I am attempting to customize the appearance of SELECT / OPTION boxes using INLINE CSS. Unfortunately, my use of background-color is not producing the desired effect: <option style='bakground-color:red'>text</option> My goal is to h ...

Create a layout consisting of two rows, each containing three blocks. Ensure that the layout is responsive by using only HTML and CSS, without relying

Hello there! I am looking to create a responsive layout without using bootstrap or any other framework..... I want to build it from scratch. https://i.stack.imgur.com/GAOkh.png I am aiming for responsive blocks that collapse into one column when the page ...

Steps for accessing the value from an input tag within the same form:

Exploring how to utilize the value "typed_from_user" in another tag within the same form, using only PHP & HTML without relying on JavaScript. Is this scenario feasible? For instance, let's say I wish to reuse the term 'pizza' <form> ...

How can I arrange a table in Angular by the value of a specific cell?

Here's the current layout of my table: Status Draft Pending Complete I'm looking for a way to sort these rows based on their values. The code snippet I've been using only allows sorting by clicking on the status header: onCh ...

Faux CSS, every other moment appears to be unsuccessful

My HTML code looks like this: <div class="container"> <div class="foo">Foo!</div> <!-- if this is red... --> <div class="bar">Bar!</div> </div> <div class="container"> <div class="foo">Foo! ...

Incorporating ajax and jquery into html: Step-by-step guide

Previously, I inquired about implementing a show/hide functionality for a div that only renders when a specific link is clicked. (View the original question) Following some advice, I was provided with jQuery and AJAX code to achieve this: function unhide() ...

What is the best way to align a container in the middle of the page without positioning the text in the center

Query 1: What is the best way to horizontally center the container div while keeping Typography aligned to the left? Expected outcome: https://i.stack.imgur.com/yKCZF.jpg Query 2: How can a component be positioned below the AppBar without relying on mar ...

Whiskey Angostura and Straight Row Set to 8, not 12

Recently, I incorporated Bourbon, Bitters, and Neat into my rails application. However, I am encountering an issue where the number of grid-columns is stuck at 8 instead of the desired 12. To address this problem, I have taken the following steps: Ensur ...

Attach a tab-icon to a picture

I am looking to add a tab to the bottom border of an image within a gallery. This tab needs to be right up against the image border with no space in between. When clicked, this tab should activate a small JavaScript function that will display the content ...

Issues with Bootstrap's hamburger menu not functioning properly when clicked

Can't seem to get my hamburger button working. I've followed the bootstrap documentation and ensured that Bootstrap and jQuery are in the correct order, but still no luck. Any suggestions on what could be causing this issue? Are my links misplace ...

Tips for incorporating inline images with gatsby-image

Seeking Solution In my quest to query and showcase images with a maximum width of 350px, I am hoping to have them displayed inline-block for tablets and larger screens. Ideally, each image would sit next to one another and wrap if they exceed the parent d ...