Menu dropdown feature for mobile site

Recently, I was working on a website and encountered an issue with the dropdown menu. Despite making the layout responsive and adding a media query for mobile devices, the dropdown menu would activate the first link automatically on mobile, giving users barely a second to respond.

I vaguely remember learning about an easy fix for this in school, something like onclick or similar. However, despite my efforts to find a solution late at night, I have been unsuccessful so far.

Here is the HTML for the dropdown menu:

<div class="nav">
    <div class="links">
        <ul id="dropdown">
            <li>
                <a href="index.html"> Tetterode </a>
                <ul>
                    <li><a href="project.html">Project</a></li>
                    <li><a href="promenade.html">Promenade</a></li>
                    <li><a href="brochure.html">Brochure</a></li>
                    <li><a href="impressies.html">Impressies</a></li>
                </ul>
            </li>
            <li>
                <a href="oplevering.html">Woningen</a>
                <ul>
                    <li><a href="oplevering.html">Oplevering</a></li>
                    <li><a href="impressies.html">Impressies</a></li>
                </ul>
            </li>
            <li class="currentpage">
                <a href="ligging.html">Locatie</a>
                <ul>
                    <li><a href="ligging.html">Ligging</a></li>
                    <li><a href="situatie.html">Situatie</a></li>
                    <li><a href="routeplanner.html" class="smaller">Route<br>planner</a></li>

                </ul>
            </li>
            <li>
                <a href="hypotheken.html">Financiering</a>
                <ul>
                    <li><a href="hypotheken.html">Hypotheken</a></li>
                </ul>
            </li>
            <li>
                <a href="makelaars.html">Contact</a>
                <ul>
                    <li><a href="makelaars.html">Makelaars</a></li>
                </ul>
            </li>               
        </ul>
    </div>
</div>

And here is the corresponding CSS:

.nav{
    width: 100%;
    height:50px;
    background-image:url("bg.jpg");
    background-repeat:repeat;
    text-align:center;
    padding-bottom:0px;
    margin-bottom:0px;
}
.links ul li {
   list-style-type: none;
   padding-right: 15px;
   height:50px;
   display:inline-block;
   padding-top:0px;
   line-height:50px;
   padding-left:14px;
   text-shadow: 3px 3px 2px rgba(0, 0, 0, 0.50);
   margin-top:0px;
}
...

Essentially, I am looking for a solution that allows me to click on the main navigation items (such as "Tetterode," "Woningen," etc.) and have the other submenu items appear without rushing through the process.

Answer №1

Take a look at this JSFIDDLE for your code.

I ran some tests on my Iphone 4 with IOS 6 and noticed that when clicking on the menu items, it redirects to the link within that menu. To fix this issue, simply remove those links and replace them with '#'. This adjustment will ensure your code functions properly on mobile sites.

For mobile site compatibility, try using this HTML structure:

<div class="nav">
    <div class="links">
        <ul id="dropdown">
            <li>
                <a href="#"> Tetterode </a>
                <ul>
                    <li><a href="project.html">Project</a></li>
                    <li><a href="promenade.html">Promenade</a></li>
                    <li><a href="brochure.html">Brochure</a></li>
                    <li><a href="impressies.html">Impressies</a></li>
                </ul>
            </li>
            <li>
                <a href="#">Woningen</a>
                <ul>
                    <li><a href="oplevering.html">Oplevering</a></li>
                    <li><a href="impressies.html">Impressies</a></li>
                </ul>
            </li>
            <li class="currentpage">
                <a href="#">Locatie</a>
                <ul>
                    <li><a href="ligging.html">Ligging</a></li>
                    <li><a href="situatie.html">Situatie</a></li>
                    <li><a href="routeplanner.html" class="smaller">Route<br>planner</a></li>

                </ul>
            </li>
            <li>
                <a href="#">Financiering</a>
                <ul>
                    <li><a href="hypotheken.html">Hypotheken</a></li>
                </ul>
            </li>
            <li>
                <a href="#">Contact</a>
                <ul>
                    <li><a href="makelaars.html">Makelaars</a></li>
                </ul>
            </li>               
        </ul>
    </div>
</div>

While it may seem like a simple solution, this is the best way to maintain the structure and CSS of your code. Happy coding!

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 instruct npm to generate a .min.css file from scss?

Currently, I have setup a process to automatically compile CSS from SCSS using a JSON script. However, the issue is that the ".min" suffix is being removed during this compilation. Here is the output from the terminal displaying the script I am running and ...

"Troubleshooting a matter of spacing in HTML5 body

I've been struggling to eliminate the gap between the top of my webpage and the <div> element. Here's the code snippet causing the issue: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="v ...

What distinctions can be made between the id selector and class selector when implementing border styles?

When trying to set the border width to 0px, I noticed that the border style doesn't seem to work when using a class selector. Oddly enough, the border width does work if an id selector is used! Below is the HTML (Vue template) code: <el-form-item ...

How can I adjust margins based on the positioning of surrounding elements?

Apologies if the title is not accurate, but I will try my best to explain clearly. If you have any ideas on how to improve it, please share, and I will make changes. Here is the issue I am facing: https://i.sstatic.net/kGMjw.png (I apologize for any lang ...

Just starting out with JavaScript - updating the appearance of an element

Based on the value of a boolean, I am looking to control the visibility of specific tabs in my sidebar when the page loads. var someVar = true; function show_ifTrue() { if (Boolean(someVar) == true) { document.getElementById('x'). ...

JavaScript does not function properly with dynamically loaded content

Trying to load the page content using the JQuery load() method. See below for the code snippet: $(window).ready(function() { $('#content').load('views/login.html'); }); .mdl-layout { align-items: center; justify-content: center ...

I'm unable to adjust the font size of the final h3 element

I'm currently designing a webpage with various titles, but I've encountered an issue. I am unable to adjust the font size of the last h3 title without affecting the rest of the titles. I'm curious as to why this is happening and how I can re ...

Slideshow box with images aligned perfectly

I have designed a container with images, but my goal is to: either show the images inline or stack them on top of each other, and then be able to navigate through them using jQuery. I attempted absolute positioning on both .box and .box img, as well as u ...

Overlapping divs are observed when utilizing absolute positioning in CSS

I am facing a challenge with placing the div identified by our_team below the div with the ID of services. When I use absolute positioning, the former ends up overlapping the latter. The services div transitions to display information when hovered over du ...

Tips for locking the position of a table header and allowing only the table body to scroll

I have designed a table with tbody consisting of 2 tr elements. One tr is used for hiding/showing data. I am trying to keep the Table header fixed while only scrolling the table body. However, as I am using angular js ng-repeat on the tbody, I am encounte ...

The arrow in the dropdown menu is missing

I recently came across this code snippet in a Boostrap 4 website: <div class="btn-group mb-2 mr-2"> <button type="button" class="btn btn-primary">Primary</button> <button type="button" cl ...

When combining <a> with the class line-through, the line does not appear

I am currently utilizing a class to replace the deprecated strike in HTML: .entfall { text-decoration: line-through; } However, when using Firefox 38.x and the following code: <span class="entfall"><a href="some link">text</a></span ...

Is there a way to make jQuery insert a placeholder before the image fades in?

I've implemented a fading effect on elements in my page using the following script: $(document).ready(function() { $('#holder').delay(650).fadeIn(1000); $('#sidepanelHolder').delay(650).fadeIn(1000); $( ...

Is it possible to modify a scss style in Prestashop?

I have encountered an issue while using a default theme in Prestashop 1.6 that I need assistance with. My goal is to move the navbar up by 25px. I understand that I should make changes to #block_top_menu { padding-top: 25px; } in blocktopmenu.scss, which ...

Issue with Jquery/Js function not performing as expected

This Javascript function is really effective in adding and removing form elements. However, I have noticed that it does not remove the class "input-group col-md-12 row" when an element is removed. I would like to modify it so that it also removes that cla ...

Keep Dropdown menu open when clicking on a menu item to avoid closing

I'm facing an issue with a drop-down menu in the sidebar that contains links as menu items. Whenever I click on a menu item (link), the link works fine but the drop-down menu closes. What I actually want is for the drop-down menu to stay open even af ...

Angular styling for input elements that are in the pristine state

Hey there, I'm working with a CSS class that applies a red border to an input field when it is required and invalid, and changes to green when it becomes valid. CSS .ng-valid[required], .ng-valid.required { border-left: 5px solid #42A948; /* green ...

I must negate the impact of the parent CSS file without directly countering it

Currently, I am developing web pages with "rtl" directionality. Within my shop.html template, I am utilizing a bootstrap component known as "breadcrumbs". As a result, I need the breadcrumbs to display from right to left. <div class="breadcrumb"> ...

Using the float property in IE7 can cause a line break and may result in other divs being pushed down

Hey there, I've encountered a few issues with floats in IE multiple times. Here's an example to illustrate what I mean. Please note that this example functions properly in Firefox and Chrome. index.html <html> <link href="style.css" rel= ...

What is the best way to adjust the width of the <span> element in an Angular application?

This snippet showcases a piece of HTML code. <div class="col-md-8"> <span class="label">Product Name</span> <span> <mat-form-field> <input matInput formControlName="productName"> </mat-form ...