Mobile responsiveness issue with menu not functioning as expected

I'm completely new to the world of responsive design with CSS. I recently created a responsive menu that works perfectly when I resize the browser window on my computer. However, when I try to access the site on my phone, the menu is just zoomed out and doesn't display correctly as it should in a responsive design.

Check out the site here

I'm really puzzled as to why this is happening. Any suggestions or insights from anyone who has experienced this before? I've set the maximum width to 900px so the menu should collapse when the window size is too small.

Here is the HTML code for the menu:

<ul class="topnav" id="myTopnav">
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Portfolio</a></li>
            <li><a href="#">Contact</a></li>
            <li class="icon">
                <a href="javascript:void(0);" onclick="myFunction()">&#9776;</a>
            </li>
        </ul>

And here is the corresponding JavaScript code:

/* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */
    function myFunction() {
        var x = document.getElementById("myTopnav");
        if (x.className === "topnav") {
            x.className += " responsive";
        } else {
            x.className = "topnav";
        }
    }

Lastly, here is the responsive CSS for the menu:

@media screen and (max-width:900px) {
    ul.topnav li {display:none;}
    ul.topnav li.icon {
        float: right;
        display: inline-block;
        opacity: 1;
    }
}
@media screen and (max-width:900px) {
    ul.topnav.responsive {position:relative;}
    ul.topnav.responsive li.icon {
        position: absolute;
        right: 0;
        top: 0;
        background-color: none; 
        opacity: 1;
    }
    ul.topnav.responsive li {
        float: none;
        display: inline;
        position: relative;
        top: 32px;
    }
    ul.topnav.responsive li a {
        display: block;
        text-align: right;
        /*background-color: red;*/
    }
}

Answer №1

Ensure you include a <meta> tag in the <head> section of your code:

<meta name="viewport" content="width=device-width, initial-scale=1">

For comprehensive information on how to utilize the <meta> tag effectively (additional values can be added to the content attribute), refer to this resource:
Using the viewport meta tag to control layout on mobile browsers

Answer №2

nvbar is designed to work seamlessly with ajax library, with the prerequisite that jquery is present on the page. Its user-friendly interface is mobile compatible, making it a versatile option for website design. For more information, you can check out an interactive menu with optional sub-menus.

<nav role="navigation" id="wb-sm" data-ajax-replace="./ajax/sitemenu-en.html" data-trgt="mb-pnl" class="wb-menu visible-md visible-lg" typeof="SiteNavigationElement">
<div class="container nvbar">
<h2>Topics menu</h2>
<div class="row">
<ul class="list-inline menu">
<li><a href="./index-en.html">WET project</a></li>
<li><a href="./docs/start-en.html#implement">Implement WET</a></li>
<li><a href="./docs/start-en.html">Contribute to WET</a></li>
</ul>
</div>
</div>
</nav>

Ensure that the data-ajax-replace element is correctly implemented to display the Menu list, and add the following footer lines at the end:

</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="./wet-boew/js/wet-boew.min.js"></script>

Answer №3

One great tool for creating responsive websites is Bootstrap. It's user-friendly and simple to implement. http://getbootstrap.com/getting-started/

You can also utilize Bootstrap to easily design menus. Check out the link below for more information

Bootstrap Menus

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

Link-defying button

I'm developing a website with a homepage that serves as an entry point to the rest of the site (it welcomes the user and allows them to click anywhere to access the main website). The following code accomplishes this: <template> <div onc ...

Enhancing Form Fields Dynamically using AJAX and JSON

I'm trying to update specific fields in my form after fetching data from a database using AJAX and JSON. Here is the code snippet: In my form: <div class="form"> <?php $form=$this->beginWidget('CActiveForm', array( ' ...

Wrapping content in flexbox and aligning it justified

I have an issue where I want to display a page title on the left side and a rating number with stars on the right side. My goal is to center all items once flexbox wraps. Specifically, when the "Longer Page Title" reaches the rating and stars and the flexb ...

Does the AngularJS Controller disappear when the DOM element is "deleted"?

One challenge I encountered is regarding a directive that is connected to an angularjs controller, as shown below: <my-directive id="my-unique-directive" ng-controller="MyController"></my-directive> In the controller, at a certain point, I ne ...

Transferring an email containing an HTML file along with embedded images

Is there a way to send HTML emails with images using C#? Can I simply insert a direct link to an image hosted on my server (similar to <img src="http://mysite.ru/img.png" />) or do I need to attach the image and then use a link to the attached file ...

Alignment of elements in a list at the bottom

I am looking to create multi-level tabs using <li> that grow from bottom to top. Here is the current code I have: div{ width: 200px; border: 1px solid black; } ul{ margin: 0px; padding: 0px; } li{ margin: 2px; width: 20px; display: ...

Having trouble loading image on web application

Currently, I am facing an issue while attempting to add a background image to an element within my Angular web application. Strangely enough, the relative path leading to the image seems to be causing my entire app to break. https://i.stack.imgur.com/b9qJ ...

What is the best way to confine the child elements within a parent element using CSS?

Check out my CSS and HTML code here: https://jsfiddle.net/z2cc11yk/ Here's the HTML: <div class="progressbar-container"> <div class="progressbar-text">125%</div> <div class="progressbar-progress" style="background-color: red; wi ...

Retrieve the CSS class definition using the console in the Chrome Developer Tools

Is there a way to automatedly extract CSS class definitions from Chrome Developer Tools? I want to retrieve the styles defined in a specific class name, similar to how it is displayed in the Styles tab on the right-hand side. I know about the getComputedS ...

Creating HTML code using Django and JavaScript

Greetings world! I am relatively new to Python and JavaScript, so my coding techniques might seem unconventional to seasoned developers. However, I am eager to learn and improve. I have an HTML page where Django generates some code for a calendar: Here&a ...

Retrieving an Instance of Google Maps Object with the Help of JQuery

I'm currently working on a script that, when executed, will retrieve an instance of a Google Maps object from the webpage using JQuery. For example, if there is a map present on the page, it will be structured like this: <div class="map">....& ...

Filling a select element in an HTML file using AJAX

I've hit a roadblock, trying to display this PHP list. <?php include 'connection.php'; $query = mysqli_query($conn, "SELECT * FROM expense_object ORDER BY code" ); ?> <!DOCTYPE html> <html lang=" ...

Background color set for only half of the div

Is it possible to achieve a design similar to this using CSS, with a Half-background color for a div? ...

Unlocking the full potential of Bootstrap with the colspan feature

I'm currently in the process of developing an Angular 2 and Bootstrap application. Here's a snippet of my code: <div class="panel-body"> <table class="table table-striped table-bordered" style="width:100%;"> < ...

Efficiently transferring time values from dynamically created list items to an input box using JavaScript

Is there a way to store a dynamically generated time value from an li element into an input box using JavaScript? I have a basic timer functionality on my website that includes starting, stopping, pausing, taking time snaps, and resetting them. These time ...

Stop a second ajax request while the first one is in progress

Despite the abundance of questions on Stack Overflow addressing this issue, I still can't find a solution. Here is the jQuery code snippet: function _get_activities_ajax() { $(".activity-accordian h3").click(function() { var catrgory ...

Tips for enlarging an image by tapping on it in handlebars

I currently have the handlebars template engine integrated with node.js, and I'm facing an issue where thumbnail images from the database are displaying at a fixed width and height of 70. Is there a way to enable users to click on these images in orde ...

Identifying Touch Interaction exclusively on WebGL Canvas within threejs

Currently, I am developing a threejs application that requires input from HTML buttons and utilizes Raycast Detection on touch within threeJS. The issue I am encountering is that when the user clicks an HTML button, the Raycast function is triggered as we ...

Issue with border in a nested table within an HTML table

I am faced with an issue in styling nested tables. My goal is to have borders on both tables, but I specifically need only the bottom border of the inner table without the top, right, and left borders. The default border style can be achieved using the fol ...

PHP Ajax login form to instantly authenticate without redirecting to a new page

After attempting to implement Ajax in my login form by following two different tutorials, I am still facing the issue of error messages redirecting to another page instead of displaying on the same page. I have tried to troubleshoot and compare my code wit ...