Select your language
Before diving into the tutorial, let’s take a moment to understand the key components we’ll be working with:
Then consider following steps to make desktop & mobile menu.
Step 1:
Create two menu type module from administrator like that and assign them two different positions as you can see in below image bc-3a & bc-3b are two positions in template.
Step 2:
Inside your template main index.php file. Consider following code: First we have countmodule method, which will show both module at once. Next we have two css classes which will hide module on desktop & mobile respectively.
Next first we will show bc-3a position and pass id mobileTopMenu(an id to be used for JavaScript function to work correctly and avoid confliction). Then we will show module positioned at bc-3b and pass id "deskTopMenu".
Step 3:
Create style layout override for that module
}
Here is code for card.php
<?php /** * @package Joomla.Site * @subpackage Templates.cassiopeia * * @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; $module = $displayData['module']; $params = $displayData['params']; $attribs = $displayData['attribs']; if ($module->content === null || $module->content === '') { return; } $moduleTag = $params->get('module_tag', 'div'); $moduleAttribs = []; $moduleAttribs['class'] = $module->position . ' card ' . htmlspecialchars($params->get('moduleclass_sfx', ''), ENT_QUOTES, 'UTF-8'); $headerTag = htmlspecialchars($params->get('header_tag', 'h3'), ENT_QUOTES, 'UTF-8'); $headerClass = htmlspecialchars($params->get('header_class', ''), ENT_QUOTES, 'UTF-8'); $headerAttribs = []; $headerAttribs['class'] = $headerClass; // Only output a header class if it is not card-title if ($headerClass !== 'card-title') : $headerAttribs['class'] = 'card-header ' . $headerClass; endif; // Add class from attributes if any if (!empty($attribs['class'])) { $moduleAttribs['class'] .= ' ' . htmlspecialchars($attribs['class'], ENT_QUOTES, 'UTF-8'); } // Only add aria if the moduleTag is not a div if ($moduleTag !== 'div') { if ($module->showtitle) : $moduleAttribs['aria-labelledby'] = 'mod-' . $module->id; $headerAttribs['id'] = 'mod-' . $module->id; else : $moduleAttribs['aria-label'] = $module->title; endif; } ?> <script> /* Toggle between showing and hiding the navigation menu links when the user clicks on the hamburger menu / bar icon */ function mobileTopMenu_<?=$attribs['id']?>(id) { var x = document.getElementById(id); if (x.style.display === "block") { x.style.display = "none"; } else { x.style.display = "block"; x.style.position="absolute"; x.style.background="#FFFFFF"; x.style.right="10px"; x.style.width="250px"; x.style.border="1px solid #EEE"; x.style.borderRadius="15px"; x.style.zIndex="9998"; } } </script> <div class="topnav_<?=$attribs['id']?> <?php //echo $class_sfx; ?>"> <a href="#home" class="active"></a> <!-- Navigation links (hidden by default) --> <div id="<?=$attribs['id']?>"> <?php echo $module->content; ?> </div> <a href="javascript:void(0);" class="icon" onclick="mobileTopMenu_<?=$attribs['id']?>('<?=$attribs['id']?>')"> <i class="fa fa-bars"></i> </a> </div> <style> /********* MENU *****************/ /* Style the navigation menu */ .topnav_<?=$attribs['id']?> { position: relative; } /* Hide the links inside the navigation menu (except for logo/home) */ .topnav_<?=$attribs['id']?> #<?=$attribs['id']?> { display: none; } /* Style navigation menu links */ .topnav_<?=$attribs['id']?> a { color: green; padding: 10px 12px; text-decoration: none; font-size: 17px; display: block; margin: 7px; } /* Style the hamburger menu */ .topnav_<?=$attribs['id']?> a.icon { background: #FFFFFF; border:1px solid green; border-radius:50%; display: block; position: absolute; right: 0; top: 0; z-index: 9999; } /* Add a grey background color on mouse-over */ .topnav_<?=$attribs['id']?> a:hover { background-color: #FFF; color: black; } .metismenu.mod-menu .metismenu-item{ padding: 1em 1em 1em .25em !important; } /* MOBILE */ @media (max-width:569px) { .metismenu.mod-menu .metismenu-item { padding: 5px 0 !important; display: block; font-size: 1rem; } .topnav_<?=$attribs['id']?> { display:block; } .headerwrapper div.container { border-radius: 25px; } .container-header nav { display:contents; } } </style>
Also check this : Desktop & Mobile menu in HTML CSS on www.abdulwaheed.pk
Hope this helped.
Still need help! no problem, feel free to contact us Today
Abdul Waheed : (Hire Joomla & PHP Pakistani Freelancer)