Of course! This is a great-sounding design. The key is to use Bootstrap's responsive display utilities to show/hide the different layouts for desktop and mobile.
Here is the complete code for your header.inc.php file. I've included detailed comments to explain how it all works.
header.inc.php
Copy and paste the code below into a file named header.inc.php.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Awesome Website</title>
<!-- Bootstrap 5.3.2 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<!-- Font Awesome 6.5.1 CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Custom CSS for the Desktop Layout -->
<style>
/* These styles ONLY apply to screens 992px and wider (Bootstrap's 'lg' breakpoint) */
@media (min-width: 992px) {
body {
/* Light blue background for the page */
background-color: #d6eaf8; /* A nice light blue */
padding: 10px; /* This gives the space for the inset effect */
}
.desktop-main-container {
/* The white container with rounded corners */
background-color: #ffffff;
border-radius: 15px;
height: calc(100vh - 20px); /* Full viewport height minus the body padding */
overflow: hidden; /* Ensures content respects the rounded corners */
display: flex; /* Use flexbox for the two-column layout */
}
.desktop-sidebar {
/* Fixed width for the left menu */
flex: 0 0 250px;
padding: 2rem 1.5rem;
border-right: 1px solid #dee2e6; /* Separator line */
}
.desktop-content {
/* The main content area takes the remaining space */
flex-grow: 1;
padding: 2rem;
overflow-y: auto; /* Allow content to scroll if it's too long */
}
}
</style>
</head>
<body>
<!-- ============================================= -->
<!-- == DESKTOP LAYOUT (Visible on LG+) == -->
<!-- ============================================= -->
<!-- 'd-none d-lg-flex' hides this on mobile and shows it as a flex container on large screens -->
<div class="desktop-main-container d-none d-lg-flex">
<!-- Left Column: Sidebar with Logo and Menu -->
<div class="desktop-sidebar">
<!-- Logo Placeholder -->
<div class="logo mb-4 text-center">
<h3><i class="fas fa-gem me-2"></i>YourLogo</h3>
</div>
<!-- Navigation Menu -->
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">
<i class="fas fa-home me-2"></i>Home
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="fas fa-box-open me-2"></i>Products
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="fas fa-info-circle me-2"></i>About Us
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="fas fa-envelope me-2"></i>Contact
</a>
</li>
</ul>
</div>
<!-- Right Column: Main Page Content -->
<div class="desktop-content">
<!-- Your page content will be loaded here -->
<!-- ============================================= -->
<!-- == MOBILE LAYOUT (Hidden on LG+) == -->
<!-- ============================================= -->
<!-- 'd-lg-none' hides this on large screens, making it mobile-only -->
<header class="d-lg-none">
<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
<div class="container-fluid">
<!-- Mobile Logo/Brand -->
<a class="navbar-brand" href="#">
<i class="fas fa-gem me-2"></i>YourLogo
</a>
<!-- Hamburger Menu Button -->
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mobileNavbar" aria-controls="mobileNavbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Collapsible Menu -->
<div class="collapse navbar-collapse" id="mobileNavbar">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!-- Main Content Container for Mobile -->
<main class="container py-4 d-lg-none">
<!-- Your page content will be loaded here -->
Important Note: The code above intentionally leaves some HTML tags open (<div class="desktop-content"> and <main>). This is because your main page content (index.php, etc.) will go inside, and the footer.inc.php will close them.
How to Use It
To see this in action, you can create a simple index.php and footer.inc.php.
1. index.php (Example Page)
This file will include your header, add some content, and then include your footer.
<?php include 'header.inc.php'; ?>
<!-- This is where your page-specific content goes. -->
<!-- It will automatically appear in the correct content area for both desktop and mobile. -->
<h1>Welcome to the Main Content Area!</h1>
<p>This is a demonstration of the responsive header layout.</p>
<p>On a large screen (wider than 992px), you should see this content inside a white, rounded container with a blue background behind it. The navigation will be on the left.</p>
<p>On a smaller screen, the layout will switch to a standard Bootstrap website with a top navigation bar that collapses into a hamburger menu. The special blue background and inset container will disappear.</p>
<div class="card mt-4">
<div class="card-body">
This is just some sample content inside a Bootstrap card to fill up space.
</div>
</div>
<?php include 'footer.inc.php'; ?>
2. footer.inc.php (The Next Step)
This file will close the open tags from the header and include the necessary JavaScript files.
</div> <!-- This closes the .desktop-content div from the header -->
</div> <!-- This closes the .desktop-main-container div from the header -->
</main> <!-- This closes the mobile <main> container from the header -->
<!-- ============================================= -->
<!-- == JAVASCRIPT LIBRARIES == -->
<!-- ============================================= -->
<!-- It's best practice to load JS at the end of the body for faster page loading -->
<!-- jQuery 3.7.1 (as requested) -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<!-- Bootstrap 5.3.2 JS Bundle (includes Popper.js) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>
</html>
Explanation of Key Concepts
- Responsive Display Utilities: The magic happens with classes like
d-none d-lg-flex and d-lg-none.
d-none: Sets display: none; by default (hiding the element).
d-lg-flex: Overrides d-none on large screens (992px and up) and sets display: flex;.
d-lg-none: Hides the element only on large screens, making it visible on medium, small, and extra-small screens.
- CSS Media Query: The
<style> block is wrapped in @media (min-width: 992px) { ... }. This ensures the blue background, inset container, and sidebar styles are only applied on desktop screens, leaving the mobile view as a standard Bootstrap site.
- Flexbox for Desktop:
display: flex on the .desktop-main-container allows for the simple two-column layout. The sidebar has a fixed width (flex: 0 0 250px), and the content area grows to fill the rest (flex-grow: 1).
- Standard Bootstrap Navbar: The mobile version uses a completely standard
navbar component, which is exactly what you'd expect from a "regular bootstrap site".
Resize your browser window after setting up these files, and you'll see the layout switch seamlessly! Let me know when you're ready for the footer.