I've been struggling to make the sidebar menu on my smartphone display horizontally with icons at the top and text at the bottom. I've tried using flex and other methods, but it still doesn't work sideways. Am I missing something?
const sidebar = document.getElementById('sidebar');
const navbarToggle = document.querySelector('.navbar-toggler');
navbarToggle.addEventListener('click', () => {
if (window.innerWidth <= 767) {
sidebar.classList.toggle('show');
}
});
body {
padding-top: 70px; /* Adjusted padding top */
}
@media (max-width: 767px) {
body {
padding-top: 56px;
}
#sidebar {
display: flex;
flex-direction: column;
background-color: #343a40;
color: #fff;
position: fixed;
bottom: 0;
left: 0;
right: 0;
width: 100%;
padding: 0.5rem;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
#sidebar .nav-link {
display: flex;
flex-direction: column;
align-items: center;
font-size: 0.8rem;
text-align: center;
padding: 0.5rem 0;
width: 100%;
}
#sidebar .nav-link i {
font-size: 1.2rem; /* Adjust icon size */
margin-bottom: 0.2rem;
}
#sidebar .nav-link.active {
font-weight: bold;
}
}
@media (max-width: 767px) and (min-width: 576px) {
#sidebar .nav-link i {
font-size: 1rem;
}
}
@media (min-width: 768px) {
#sidebar {
display: block;
position: sticky;
top: 0;
}
}
#sidebar .nav-link span {
display: block;
}
#sidebar .nav-link i {
margin-bottom: 0.25rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0 >
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<ahref="/cdn-cgi/l/email-protection"class="__cf_email__"data-cfemail="7c1e1313080f080e1d0c3c49524e524c">[email protected]</a>/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<link rel="stylesheet" href="styles.css">
<title>Complex Navbar and Sidebar</title>
</head>
...
(I omitted the rest of the code for brevity)
...
<script src="https://cdn.jsdelivr.net/npm/<ahref="/cdn-cgi/l/email-protection"class="__cf_email__" data-cfemail="89ebe6e6fdfafdfbe8f9c9bca7bba7b9">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
<script src="script.js"></script>
</body>
</html>
I would appreciate any help or explanation as to why the sidebar layout isn't changing accordingly.
I'm looking to adjust the sidebar to display vertically on a PC or tablet screen, and horizontally at the bottom of the screen with icons above the text when viewed on a smartphone. Thank you!