The issue with CSS Vertical Navigation Menu Drop Down not functioning in Internet Explorer 11

My CSS navigation menu isn't functioning in IE11, although it works perfectly in Chrome and Firefox. The menu is purely CSS-based with no JavaScript involved. I've tried playing around with doctype declarations but haven't been able to resolve the issue.

Can someone please help me figure out what I might be overlooking?

nav ul {
margin-top:1px; /* tucks the child ul up close to the parent li */
border-color: blue;
border-width: 10px;
border-style: solid;
width: 200px;
overflow: hidden;
}
nav li {
list-style-type: none;
border-color: aqua;
border-width: 10px;
border-style: solid;
}
nav ul li {
display: none;
border-color: lime;
border-width: 10px;
border-style: solid;
margin:1px;
margin-top:-10px;
margin-left:-10px;
}
nav {
background-color: #c8b99c;  /* pale brown */
width: 220px;
margin-left:auto;
margin-right: auto;
}
nav ul li.selected {
background-color: #c18946;
}
nav li a {  /* to make the whole box clickable, not just the link text */
display:block; /* <<< this is the bit that does it */
line-height:23px;
text-decoration:none;
border-color: red;
border-width: 3px;
border-style: solid;
}
nav li:focus-within ul li {
display: block;
}
<!doctype html>
<html lang="en">
<head>
<title>My Webpage</title>
<link type="text/css" rel="stylesheet" href="nav_style.css">
</head>
<body>
<nav>
<li tabindex="1"><a href="#" tabindex="-1">Home</a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Skeleton Page 1</a></li>
<li><a href="#">Skeleton Page 2</a></li>
</ul>
</li>
<li tabindex="1"><a href="#" tabindex="-1">Home</a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Skeleton Page 1</a></li>
<li><a href="#">Skeleton Page 2</a></li>
</ul>
</li>
</nav>
</body>
</html>

Answer №1

To achieve this effect using the focus property, you can write the following code:

nav li:focus ul li,
nav li a:focus + ul li{
    display: block;
}

For more information on CSS selectors, visit this link.

The selector div + p targets all <p> elements that come immediately after <div> elements.

nav ul {
margin-top:1px; /* tucks the child ul up close to the parent li */
border-color: blue;
border-width: 10px;
border-style: solid;
width: 200px;
overflow: hidden;
}
nav li {
list-style-type: none;
border-color: aqua;
border-width: 10px;
border-style: solid;
}
nav ul li {
display: none;
border-color: lime;
border-width: 10px;
border-style: solid;
margin:1px;
margin-top:-10px;
margin-left:-10px;
}
nav {
background-color: #c8b99c;  /* pale brown */
width: 220px;
margin-left:auto;
margin-right: auto;
}
nav ul li.selected {
background-color: #c18946;
}
nav li a {  /* to make the whole box clickable, not just the link text */
display:block; /* <<< this is the bit that does it */
line-height:23px;
text-decoration:none;
border-color: red;
border-width: 3px;
border-style: solid;
}
nav li:focus ul li,
nav li a:focus + ul li{
display: block;
}
<!doctype html>
<html lang="en">
<html>
<head>
<title>My Webpage</title>
<link type="text/css" rel="stylesheet" href="nav_style.css">
</head>
<body>
<nav>
<li tabindex="1"><a href="#" tabindex="-1">Home</a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Skeleton Page 1</a></li>
<li><a href="#">Skeleton Page 2</a></li>
</ul>
</li>
<li tabindex="1"><a href="#" tabindex="-1">Home</a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Skeleton Page 1</a></li>
<li><a href="#">Skeleton Page 2</a></li>
</ul>
</li>
</nav>
</body>
</html>

Answer №2

Here is an alternative solution for you:

You could also incorporate this layout by using nav li a:focus ~ ul li.

I hope this information proves to be useful.

  nav ul {
  margin-top:1px; /* positions the child ul close to the parent li */
  border-color: blue;
  border-width: 10px;
  border-style: solid;
  width: 200px;
  overflow: hidden;
}
nav li {
  list-style-type: none;
  border-color: aqua;
  border-width: 10px;
  border-style: solid;
}
nav ul li {
  display: none;
  border-color: lime;
  border-width: 10px;
  border-style: solid;
  margin:1px;
  margin-top:-10px;
  margin-left:-10px;
}
nav {
  background-color: #c8b99c;  /* light brown */
  width: 220px;
  margin-left:auto;
  margin-right: auto;
}
nav ul li.selected {
background-color: #c18946;
}
nav li a {  /* makes entire box clickable, not just the link text */
  display:block; /* <<<< This is important */
  line-height:23px;
  text-decoration:none;
  border-color: red;
  border-width: 3px;
  border-style: solid;
}
nav li:focus ul li,
nav li a:focus ~ ul li{
    display: block;
}
<!doctype html>
<html lang="en">
<html>
<head>
  <title>My Webpage</title>
  <link type="text/css" rel="stylesheet" href="nav_style.css">
</head>
<body>
  <nav>
      <li tabindex="1"><a href="#" tabindex="-1">Home</a>
      <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">Skeleton Page 1</a></li>
      <li><a href="#">Skeleton Page 2</a></li>
      </ul>
      </li>
      <li tabindex="1"><a href="#" tabindex="-1">Home</a>
      <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">Skeleton Page 1</a></li>
      <li><a href="#">Skeleton Page 2</a></li>
      </ul>
      </li>     
  </nav>              
</body>
</html>

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

What is the best way to use jQuery to toggle the hidden class on an inner div when a button inside a card is clicked?

How can I implement jQuery functionality to toggle the hidden class on an inner div by clicking a button inside a card? I attempted to create a container div containing multiple cards. The issue arises when I click the button - it only opens the panel, bu ...

CSS for when the mouse hovers over an element

Two php files and a js file are involved in this scenario. The issue at hand is that when the div is clicked, it navigates to a new page with an appended # to the URL, causing it to scroll to the specified comment ID. However, instead of scrolling to the c ...

Page alignment cannot be achieved using the body selector, but can be achieved with the div page wrap

Hey there, currently working on a HTML site and encountered an issue with centering the page. The code looks like this: HTML: <body> --Rest of code-- </body> CSS: body{ width:70%; margin-left:auto; margin-right:auto; } ...

Dynamic resizing of grids using React and TypeScript

I'm attempting to create a dynamic grid resizing functionality in React and TypeScript by adjusting the lgEditorSize value on onClick action. Setting the initial lgEditorSize value const size: any = {}; size.lgEditorSize = 6; Adjusting the lgEditorS ...

How can JQuery be utilized to extract the information stored in the "value" parameter of a chosen option?

I have a dropdown menu that dynamically populates its options with numbers. Here is the code for that: <select name="TheServices" id="services-selector"> <option value="" disabled selected hidden>Static Select ...

Changing the onclick function of an element with JavaScript

Is it possible to update the destination URL of a button using onclick? <div id="my_button" onclick="window.location.replace('/destination1')">Button<div> What if I wanted to change it to this? <div id="my ...

The term "Highcharts does not exist"

I'm encountering an issue with my code: <html> <head> <title><%=sAtaskaitaTitle%></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name=vs_targetSchem ...

Content Security Policy (CSP) recommendations for CSS files that are

I am facing an issue where a third-party JavaScript file is being loaded into my application, which then injects an iframe onto the page. This iframe subsequently loads its own JavaScript that creates an inline style tag in the parent window. Due to this ...

Adjust Element Width Based on Scroll Position

I'm attempting to achieve a similar effect as seen here: (if it doesn't work in Chrome, try using IE). This is the progress I've made so far: http://jsfiddle.net/yuvalsab/op9sg2L2/ HTML <div class="transition_wrapper"> <div ...

KineticJs: Enhancing Rotation with Multitouch Capability

Currently, I have a click event implemented in my code that rotates my puzzle piece by 90 degrees when clicked. However, I would like to change it from a mouse click to a touch event. How can I achieve this? Thank you. piecesArray[i][j].shape.on("mous ...

Tips for avoiding cursor sticking in css rotate transform in firefox?

I have a unique challenge in this code where I want the user to grab the black square and rotate it around the inner circle. Check out the code snippet here. While attempting to rotate the square, you might notice that the cursor sometimes gets stuck in ...

The CSS class is not properly implemented in the React component

I value your time and assistance. I have spent many hours trying to solve this issue but seem unable to reach a resolution. Here is the React component in question: import styles from './style.scss'; class ButtonComponent extends React.Compone ...

Javascript unable to update the DOM

I've been working on a project to prototype a simple functionality using JavaScript for learning purposes. However, I've encountered an issue where the contents within the <p> tag are not updating, and I'm currently stuck. Here's ...

Developing a Java applet for the purpose of showcasing it in a web browser

As I embark on the journey of creating a basic Java applet to showcase my program's output in a web browser, I find myself facing unfamiliar territory. To gain a grasp on how applets function, I decided to follow a tutorial and create a simple "Hello ...

Transforming HTML-encoded JSON into JSON format with BeautifulSoup

Seeking a solution with parsing raw HTML from the bandsintown website using beautifulSoup to access a JSON embedded in a script, particularly the "eventsJsonLd" key in the script section of the page source: "jsonLdContainer":{"eventsJsonLd":[{"@context":" ...

Is jQuery the solution for tidying up messy HTML code?

Is there a way to clean up this markup using jQuery? <span style="font-size:19px"> <span style="font-size:20px"> <span style="font-size:21px"> Something </span> </span> </span> I'm looking to tra ...

Converting CSS code into JavaScript

I am currently working with the following code: .mr15 > * margin-right: 15px &:last-child margin-right: 0 I need help translating this code to Javascript. Should I use JQuery or pure Javascript for this scenario? Thank you. ...

Footer mysteriously collapses despite being set to a fixed size + odd performance

I've been working on a web page that features a fixed Navigation bar and Footer for logging information. Both the content and the footer are designed to scroll if needed. Thanks to some experimentation and the valuable input from those who responded t ...

Reposition the jQuery tooltip arrow

I need help adjusting the position of the arrow to the left near the text box. Can anyone assist with this? Here's what I've tried so far: Check out the working example here: http://jsfiddle.net/b8fcg/ HTML: <input id="test" title="We ask ...

Ensure that the fixed element adheres to the overflow:hidden property

It's truly baffling that I can't figure this out! Is there a way to make a fixed element respect the overflow setting? I created a fiddle for reference - http://jsfiddle.net/REk4C/7/ In the fiddle and the image above, you'll notice a cont ...