This topic is locked

make your Navbar and Menu mobile friendly and attractive.

7/31/2025 11:59:33 PM
PHPRunner Tips and Tricks
P
ppradhan@live.com author

Guys, if you want to make your PHPRunner Navbar and Menu visually attractive & mobile friendly as left drawer menu, just copy-paste following codes at 'Custom_CSS' and 'Custom_functions.js' respectively. Happy tweak at PHPRunner.

code for 'Custom_CSS' in the style section:
/ === BASE === /
body {
font-family: "Segoe UI", sans-serif;
transition: background 0.3s, color 0.3s;
background-color: #fff;
color: #000;
}
/ === NAVBAR === /
.r-topheader, .navbar-default {
background-color: #0056b3 !important;
position: sticky;
top: 0;
z-index: 1000;
border: none !important;
}
.navbar-default .navbar-nav > li > a {
color: #ffffff !important;
font-weight: 500;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li.active > a {
background-color: #cc0000 !important;
border-radius: 6px;
}

/ === MOBILE ONLY === /
@media (max-width: 768px) {
body.drawer-open {
overflow: hidden;
}
.navbar-toggle {
padding: 0px 8px;
background: none;
border: none;
font-size: 1.6em;
position: relative;
z-index: 1102;
}
.navbar-toggle .icon-bar {
display: none !important;
}
.navbar-toggle::before {
content: "\2630";
color: #fff;
font-weight: bold;
font-family: Arial, sans-serif;
transition: color 0.3s ease;
}
.navbar-toggle:hover::before, .navbar-toggle:focus::before {
color: #cc0000;
}
.navbar-collapse {
position: fixed !important;
top: 0;
left: -260px;
width: 260px;
height: 100vh;
background-color: #0056b3 !important;
transition: left 0.3s ease;
padding: 0;
overflow-y: auto;
z-index: 1100;
display: flex;
flex-direction: column;
}
.navbar-collapse.active {
left: 0 !important;
}
.navbar-collapse::before {
content: "";
display: block;
height: 0;
}
.navbar-collapse .drawer-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 15px 20px 10px;
}
.drawer-title {
font-size: 18px;
font-weight: bold;
color: white;
}
.drawer-close-btn button {
background: #cc0000;
color: white;
font-size: 20px;
width: 32px;
height: 32px;
border-radius: 50%;
border: none;
cursor: pointer;
transition: background 0.3s ease;
}
.drawer-close-btn button:hover {
background: #ff3333;
}
.navbar-nav {
padding: 5px 5px;
}
.navbar-nav > li > a {
display: block;
padding: 12px 20px !important;
border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

/* === DESKTOP ONLY === */
@media (min-width: 769px) {
.navbar-collapse .drawer-header {
display: none !important;
}
/* === Drawer Header === */
.drawer-header {
display: flex;
justify-content: space-between;
align-items: center;
background: linear-gradient(to right, #0056b3, #cc0000);
padding: 12px 16px;
color: white;
font-size: 18px;
font-weight: bold;
position: sticky;
top: 0;
z-index: 1102;
}
.drawer-header .drawer-title {
display: flex;
align-items: center;
gap: 10px;
}
.drawer-header .drawer-logo {
width: 100px;
height: auto;
border-radius: 4px;
}
.drawer-header .drawer-close {
background: none;
border: none;
font-size: 26px;
color: white;
cursor: pointer;
font-weight: bold;
transition: transform 0.3s ease;
}
.drawer-header .drawer-close:hover {
transform: rotate(90deg);
}
/* === Slide Animation === */
@media (max-width: 768px) {
.navbar-collapse {
transition: transform 0.3s ease-in-out;
transform: translateX(-100%);
}
.navbar-collapse.active, .navbar-collapse.slide-in {
transform: translateX(0);
}
/* === USER INFO DRAWER FOOTER (MOBILE) === */
@media (max-width: 768px) {
.drawer-userinfo {
position: sticky;
bottom: 0;
background-color: #004a99;
padding: 10px 16px;
border-top: 1px solid rgba(255,255,255,0.2);
z-index: 1101;
}
.drawer-userinfo .dropdown-toggle {
color: white !important;
background: none !important;
font-weight: 500;
padding: 6px 12px;
border-radius: 4px;
border: 1px solid rgba(255,255,255,0.25);
width: 100%;
text-align: left;
}
.drawer-userinfo .dropdown-menu {
position: relative;
background-color: #ffffff;
margin-top: 8px;
border-radius: 6px;
box-shadow: 0 2px 10px rgba(0,0,0,0.15);
padding: 8px 0;
width: 100%;
}
.drawer-userinfo .dropdown-menu li a {
padding: 8px 16px;
font-size: 14px;
color: #333;
display: block;
}
.drawer-userinfo .dropdown-menu li a:hover {
background-color: #f0f0f0;
}
body.dark-mode .drawer-userinfo {
background-color: #1f1f1f;
border-top: 1px solid rgba(255,255,255,0.1);
}
body.dark-mode .drawer-userinfo .dropdown-toggle {
color: #fff !important;
border-color: rgba(255,255,255,0.2);
}
body.dark-mode .drawer-userinfo .dropdown-menu {
background-color: #2a2a2a;
}
body.dark-mode .drawer-userinfo .dropdown-menu li a {
color: #eaeaea;
}
body.dark-mode .drawer-userinfo .dropdown-menu li a:hover {
background-color: #333;
}
/* === Enhanced Drawer User Info === */
.drawer-userinfo {
padding: 14px 16px;
border-top: 1px solid rgba(255,255,255,0.15);
background: linear-gradient(to right, #004a99, #0066cc);
border-radius: 0 0 10px 10px;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.drawer-userinfo .dropdown-toggle {
width: 100%;
text-align: left;
background: rgba(255,255,255,0.08);
border: 1px solid rgba(255,255,255,0.2);
color: white;
padding: 12px 16px;
border-radius: 8px;
font-weight: 500;
font-size: 15px;
display: flex;
justify-content: space-between;
align-items: center;
}
.drawer-userinfo .dropdown-toggle:hover {
background: rgba(255,255,255,0.15);
}
.drawer-userinfo .dropdown-menu {
display: none;
margin-top: 10px;
background-color: #ffffff;
padding: 10px 0;
border-radius: 6px;
box-shadow: 0 4px 14px rgba(0,0,0,0.25);
animation: fadeIn 0.3s ease-in-out;
}
.drawer-userinfo .dropdown-menu.show {
display: block;
}
.drawer-userinfo .dropdown-menu li a {
padding: 10px 18px;
font-size: 14px;
color: #333;
display: block;
transition: background 0.2s ease;
}
.drawer-userinfo .dropdown-menu li a:hover {
background-color: #f4f4f4;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-6px);
}
to {
opacity: 1;
transform: translateY(0);
}
body.dark-mode .drawer-userinfo {
background: linear-gradient(to right, #1f1f1f, #2a2a2a);
}
body.dark-mode .drawer-userinfo .dropdown-toggle {
color: #fff;
background: rgba(255,255,255,0.05);
border-color: rgba(255,255,255,0.15);
}
body.dark-mode .drawer-userinfo .dropdown-menu {
background-color: #2e2e2e;
}
body.dark-mode .drawer-userinfo .dropdown-menu li a {
color: #ddd;
}
body.dark-mode .drawer-userinfo .dropdown-menu li a:hover {
background-color: #3a3a3a;
}
Code for 'Custom_functions.js':

/* NAVBAR AND MENU - RESPONSIVE */

function setupMobileMenuToggle() {
const toggleBtn = document.querySelector(".navbar-toggle");
const drawer = document.querySelector(".navbar-collapse");

if (!toggleBtn || !drawer) return;

function toggleDrawer() {
const isOpen = drawer.classList.contains("active");
if (isOpen) {
drawer.classList.remove("active");
document.body.classList.remove("drawer-open");
} else {
void drawer.offsetWidth;
drawer.classList.add("active");
document.body.classList.add("drawer-open");
}
}

toggleBtn.addEventListener("click", function (e) {
e.preventDefault();
e.stopPropagation();
toggleDrawer();
});

document.addEventListener("click", function (e) {
const isDrawerOpen = drawer.classList.contains("active");
if (
isDrawerOpen &&
!drawer.contains(e.target) &&
!toggleBtn.contains(e.target)
) {
drawer.classList.remove("active");
document.body.classList.remove("drawer-open");
}

document.querySelectorAll(".navbar-nav li.dropdown.open").forEach((item) => {
if (!item.contains(e.target)) {
item.classList.remove("open");
}
});

});

// Dropdown click fix (works for desktop and mobile)
document.querySelectorAll(".navbar-nav li.dropdown").forEach(item => {
const trigger = item.querySelector("a[data-menu-link]");
if (!trigger) return;

trigger.addEventListener("click", function (e) {
const isMobile = window.innerWidth < 769;
const hasSubmenu = item.querySelector(".dropdown-menu");

if (hasSubmenu && (isMobile || trigger.getAttribute("href") === "#")) {
e.preventDefault();
e.stopPropagation();

document.querySelectorAll(".navbar-nav li.dropdown.open").forEach(openItem => {
if (openItem !== item) openItem.classList.remove("open");
});

item.classList.toggle("open");
}
});

});

// Allow link navigation unless dropdown
document.querySelectorAll(".navbar-nav a").forEach(link => {
link.addEventListener("click", (e) => {
const parentLi = link.closest("li");
const isDropdown = parentLi && parentLi.classList.contains("dropdown");
const drawerOpen = drawer.classList.contains("active");

if (window.innerWidth < 769 && !isDropdown && drawerOpen) {
drawer.classList.remove("active");
document.body.classList.remove("drawer-open");
}
});

});
}

document.addEventListener("DOMContentLoaded", setupMobileMenuToggle);

function setupDrawerHeader() {
const drawer = document.querySelector(".navbar-collapse");
if (!drawer || window.innerWidth >= 769 || document.querySelector(".drawer-header")) return;

const header = document.createElement("div");
header.className = "drawer-header";
header.innerHTML = <div class='drawer-title'> <img src='#' alt='logo' class='drawer-logo'> <span>Corp</span> </div> <button class='drawer-close' aria-label='Close Drawer'>×</button> ;

drawer.prepend(header);

header.querySelector(".drawer-close").addEventListener("click", () => {
drawer.classList.remove("active", "slide-in");
document.body.classList.remove("drawer-open");
});
}

document.addEventListener("DOMContentLoaded", function () {
setTimeout(() => {
setupDrawerHeader();
}, 100);
});

function injectUserMenuToDrawer() {
const drawer = document.querySelector(".navbar-collapse");
const userInfoBlock = document.querySelector('[data-itemid="username_button"]');

if (!drawer || !userInfoBlock || window.innerWidth >= 769 || document.querySelector(".drawer-userinfo")) return;

const wrapper = document.createElement("div");
wrapper.className = "drawer-userinfo";
wrapper.innerHTML = userInfoBlock.innerHTML;

userInfoBlock.style.display = "none";
drawer.appendChild(wrapper);

const dropdownToggle = wrapper.querySelector(".dropdown-toggle");
if (dropdownToggle) {
dropdownToggle.addEventListener("click", function () {
const dropdownMenu = wrapper.querySelector(".dropdown-menu");
dropdownMenu.classList.toggle("show");
});
}

wrapper.querySelectorAll(".dropdown-menu li a").forEach(link => {
link.addEventListener("click", () => {
drawer.classList.remove("active");
document.body.classList.remove("drawer-open");
});
});
}

document.addEventListener("DOMContentLoaded", () => {
setTimeout(() => {
injectUserMenuToDrawer();
}, 150);
});

Sergey Kornilov admin 8/1/2025

Thank you for sharing!

I think adding a couple of screenshots here would be highly benefitial so people can understand what exactly this is all about.