Create a Responsive Menu in HTML/PHP?

Introduction

In this tutorial, we will learn how to create a responsive menu in HTML/PHP. A responsive menu is an essential part of any website as it allows users to navigate through different pages or sections easily. We will also provide a live example to demonstrate the implementation of a responsive menu.

Step 1: HTML Markup

<html>
    <head>
        <title>Responsive Menu</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div class="mobile-menu" id="mobile-menu">
            Menu
            <img src="http://www.shoredreams.net/wp-content/uploads/2014/02/show-menu-icon.png">
        </div>
        <nav>
            <ul>
                <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>
            </ul>
        </nav>
        <script type="text/javascript">
	$(function() {
        var pull = $('#mobile-menu');
        menu = $('nav ul');
        menuHeight = menu.height();
        $(pull).on('click', function(e) {
            e.preventDefault();
            menu.slideToggle();
        });
        $(window).resize(function() {
            var w = $(window).width();
            if (w > 320 && menu.is(':hidden')) {
                menu.removeAttr('style');
            }
        });
    });
        </script>
    </body>
</html>

Step 2:- Create CSS Page

nav ul{

	padding: 2px;

	margin: 0px;

	position: absolute;

	background-color: #fff;

	border: 1px solid #078EE5;

}

nav ul li{

	margin: 5px;

	float: left;

	list-style: none;

	line-height: 30px;

	position: relative;

	border: 1px solid #078EE5;

	background-color: #078EE5;

}

nav ul li:hover{

	margin: 5px;

	color: #078EE5;

	background-color: #fff;

	border: 1px solid #078EE5;

}

nav ul li:hover > a{

	color: #078EE5;

}

nav ul li a{

	color: #fff;

	padding: 10px;

	text-decoration: none;

}

.mobile-menu{

	background-color: red;

	position: relative;

	display: none;

}

@media (max-width: 640px) {

	.mobile-menu{

		display: block;

		background-color: #078EE5;

		color: #fff;

		padding: 5px 10px;

		cursor: pointer;

	}

	.mobile-menu img{

		width: 25px;

		top: 2px;

		right: 10px;

		position: absolute;

	}

	nav{

	    position: relative;

	    height: auto;

	}

	nav ul{

		display: none;

	    list-style: none;

	    padding: 0;

	    margin: 0;

	    width: 99%; 

	    top: 0;

	    position: absolute;

	}

	nav ul li{ 

		width: 92%;

		position: relative;

	    padding: 5px;

	    background-color: #078EE5;

	    cursor: pointer;

	}

}

Output:- In mobile view

Hopefully, It will help you…!!!

Related Posts

Understanding Event Correlation Tools in DataOps: Complete Guide

Introduction Modern enterprise data architectures run hundreds of pipelines every day. Data flows continuously from relational databases, cloud stores, third-party APIs, and streaming brokers into analytical data…

Read More

How AI Enhances DataOps Platforms: The Ultimate Guide to Intelligent Data

Introduction Modern enterprises are generating unprecedented volumes of data across distributed cloud data platforms, SaaS applications, operational databases, and edge devices. Extracting real-time, high-value insights from these…

Read More

DataOps Tools for Continuous Integration and Delivery: A Step-by-Step Blueprint

Introduction In the modern enterprise landscape, data is no longer merely an analytical byproduct of operations—it is the primary driver of strategic decisions, real-time customer experiences, and…

Read More

The Complete SEO Playbook for AI Guest Post Generation and Publishing

Introduction Search engine optimization relies heavily on authority, relevance, and trust. While search algorithms continually evolve, securing high-quality backlinks through strategic content placement remains a foundational ranking…

Read More

Top Digital Marketing Workflow Management Tools for Agencies

Introduction Managing a modern digital marketing stack often feels like juggling dozens of disconnected software subscriptions. Marketing managers, agency owners, and SEO specialists frequently find themselves jumping…

Read More

AI Prompt Management Tools: From Basic Prompts to High-Value Digital Assets

Generative artificial intelligence has fundamentally altered how modern enterprises, creative teams, and technical engineers operate. However, as organizations increase their reliance on large language models (LLMs), a…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x