Is there a way to include clickable links within my dropdown menu?

I'm having an issue trying to create a dropdown menu with links on my website, but it doesn't seem to be working.

<!doctype html>
<html>
<head>
    <style>
    a.mainhrf ul.mainul
    {
        display: none;
    }
    a.mainhrf:hover ul.mainul
    {
        display: block;
    }
    a.mainhrf ul.mainul li
    {
        display: block;
    }
    </style>
</head>
<body>
    <a class="mainhrf" href="#">Siemaza
        <ul class="mainul">
            <li><a href="#">A</a></li>
            <li><a href="#">B</a></li>
        </ul>
    </a>
</body>
</html>

It seems that without an a element inside the li, the dropdown works fine.

<!doctype html>
<html>
<head>
    <style>
    a.mainhrf ul.mainul
    {
        display: none;
    }
    a.mainhrf:hover ul.mainul
    {
        display: block;
    }
    a.mainhrf ul.mainul li
    {
        display: block;
    }
    </style>
</head>
<body>
    <a class="mainhrf" href="#">Siemaza
        <ul class="mainul">
            <li></li>
            <li></li>
        </ul>
    </a>
</body>
</html>

I would greatly appreciate any help or suggestions you can provide! :)

Answer №1

The issue arises from nesting a tags within each other...

To resolve this, change the parent element to a div and it should work correctly.

.mainul {
  display: none;
}
.mainhrf:hover .mainul {
  display: block;
}
<div class="mainhrf">Siemaza
  <ul class="mainul">
    <li><a href="#">A</a></li>
    <li><a href="#">B</a></li>
  </ul>
</div>

Check out the JSFiddle example: https://jsfiddle.net/vvub9wnj/

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

Display each element of the list on its own line

I have a code snippet that I'm using to display each element of a list on a separate line: ans = [multiplayer_msg, rockstar_msg, reddead_msg, crashbandicoot_msg, splitscreen_msg, codemasters_msg, wildewesten_msg, sports_msg, voor18_msg, september_msg ...

Aligning container - property: inline-block;

Having trouble centering two divs that are set to "display: inline-block;" in your code? Removing the inline-block class centers them, but they end up stacking vertically instead of horizontally. See below for an example: #news { background-image: url ...

Tips for positioning the title of a card in Bootstrap-Vue

I'm currently working with the <b-card> component from bootstrap-vue and encountering an issue where I am unable to center align the title property. Does anyone have a solution for this problem? Below you can find the structure of my card, which ...

JQuery Load fails to load in real-time

I have a PHP file where I am using JQuery to load the content of another file called 'live.php' which should display the current time, but for some reason it is not loading live. Can anyone help me troubleshoot this issue? It used to work perfect ...

HTML/CSS Selecting Tables: First, Last, and More

Is there a way to combine selector tags in order to style the first <td> inside the first <tr>? I have attempted various methods to merge these selectors, albeit unsuccessfully. I am simply seeking guidance on whether or not this is even possi ...

Issue with JAWS screen reader failing to announce aria-expanded status

My aim is to ensure that the collapsed state is accessible in both NVDA and JAWS, but I am encountering issues with it displaying properly in JAWS. Does anyone have any suggestions on how to rectify this? I have included images of the code and link list b ...

Transmitting an image from an HTML file to a Node.js server

Hello, I am currently working on capturing frames from a video and converting them into images. However, I am encountering an issue when passing this image to server.js as I am unable to access it and the console shows its type as undefined. Below is the s ...

Tips for using Jquery to retrieve HTML from external sources

I have successfully managed to display an internal webpage on my HTML, as shown below: <!doctype html> <html> <head> <script type="text/javascript" src="jquery-1.4.4.js"></script> </head> <body> & ...

How to make Vuetify grid columns wrap and fill the full height

I am facing an issue where the component created using v-card in a grid system does not fill the full height. I tried using d-flex but it did not work as expected. The middle column with a white v-card should occupy the entire column height but it is gett ...

Can the width of an offcanvas panel be adjusted?

Currently implementing the offcanvas component in my project, but I'm looking to make the panel wider than the standard size. Specifically, I want it to be 35% width. I've attempted to utilize the panelClass NgbOffcanvasOptions property, however, ...

Is there a way to alter the appearance of an HTML element without an ID using a JavaScript function?

I have a specific goal in mind, but I'm struggling to articulate it concisely. Despite conducting extensive research, none of the suggested solutions seem applicable in my case. Objective: I aim to change the background color of a div based on the da ...

What are the security risks of evaluating user-supplied strings in web browser storage?

I'm in the final stages of developing a script that creates an API for performing storage operations across various web browser storage technologies. Currently, I am focusing on adding conditional retrieval and removal functionalities. These features ...

Adjust the x-scroll to continue infinitely while deactivating the y-scroll

https://i.sstatic.net/KmDTe.png Is there a method in CSS to prevent vertical scrolling and have all the contents of a div positioned next to each other so that they extend beyond the visible browser window? I would like to enable horizontal scrolling to b ...

Exploring the art of styling in Angular6

I am looking to change the text color when a specific ID is clicked <nav class="navbar "> <ul class="navbar-nav"> <li *ngFor="let item of items"> <a class="nav-link" >{{item.title}}</a> ...

The CSS dropdown menu is malfunctioning on Internet Explorer and Firefox

After searching for a solution and coming up empty-handed, I have decided to ask a question. The drop-down menu on my computer and other devices at home works perfectly in Chrome but not in Firefox and IE. #menu { position: absolute; left: 50%; bottom ...

Within jQuery lies the power to perform multiplication operations effortlessly

I'd like to accomplish this using jQuery: var menuItems = document.getElementsByTagName("li"); for (var k = 0; k < menuItems.length; k++) { if (menuItems[k].className == "menu") { var child = menuItems[k].firstChild; if ...

Expanding text area size dynamically in Nuxt3 using Tailwind CSS

Is there a way to expand the chat input field as more lines are entered? I want the textarea height to automatically increase up to a maximum of 500px, and adjust the height of .chat-footer accordingly. Below is a snippet of my code. <div v-if="ac ...

Creating a dynamic layout of 9 divs in a fluid 3x3 grid

Fiddle | FullScreen UPDATE : New Fiddle | FullScreen View The code snippet provided demonstrates the creation of a grid with dimensions of 3x3, consisting of 9 div elements (with 8 cloned using jQuery). The horizontal alignment of the grid has been ac ...

Is there a way to show an element on a website only when the height of the HTML content exceeds the height of the viewport?

My webpage serves as a dynamic to-do list, allowing users to add an endless number of tasks of all types. As the list grows in size, the page height increases and a scrollbar appears. Positioned at the bottom right corner of the page is a fixed button that ...

IE10 has a problem with the height being set to 100%, but it seems to work fine in Quirks mode in IE and all

Check out this page for reference: I've noticed an issue with scrolling in Internet Explorer, while other browsers seem to be fine. Can you help me understand why IE is causing the scroll and how I can fix it? Thank you, Judson Here's the cod ...