Design a Responsive Navbar and Footer using Static CSS
π Introduction
A professional website always has:
- β Navbar (top navigation)
- β Footer (bottom section)
π We design them using static CSS and reuse across pages.
π― Program Statement
π Design a responsive navbar and footer using static CSS.
π§ Concept
π We will:
- Create CSS file
- Create navbar + footer
- Use static + reusable structure
βοΈ Step 1: Static Folder Structure
π Project Structure:
myproject/
static/
css/
style.css
βοΈ Step 2: Create CSS File
π File: style.css
πΉ Path:
myproject/static/css/style.css
πΉ Code:
/* Navbar */
.navbar {
background-color: #333;
overflow: hidden;
}
.navbar a {
float: left;
color: white;
padding: 14px 20px;
text-decoration: none;
}
.navbar a:hover {
background-color: #575757;
}
/* Footer */
.footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
position: fixed;
bottom: 0;
width: 100%;
}
/* Responsive */
@media screen and (max-width: 600px) {
.navbar a {
float: none;
display: block;
text-align: center;
}
}
βοΈ Step 3: Create Template
π File: layout.html
πΉ Path:
myproject/templates/layout.html
πΉ Code:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>Navbar & Footer</title>
<link rel="stylesheet" href="{% static 'css/style.css' %}">
</head>
<body>
<!-- Navbar -->
<div class="navbar">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</div>
<!-- Content -->
<div style="padding:20px;">
<h1>Welcome Page</h1>
<p>This page contains a responsive navbar and footer.</p>
</div>
<!-- Footer -->
<div class="footer">
<p>Β© 2026 My Website | All Rights Reserved</p>
</div>
</body>
</html>
βοΈ Step 4: Create View
π File: views.py
πΉ Path:
myproject/myapp/views.py
πΉ Code:
from django.shortcuts import render
def layout_page(request):
return render(request, 'layout.html')
βοΈ Step 5: URL Mapping
π File: urls.py
πΉ Path:
myproject/myproject/urls.py
πΉ Code:
from django.contrib import admin
from django.urls import path
from myapp import views
urlpatterns = [
path('admin/', admin.site.urls),
path('layout/', views.layout_page),
]
βοΈ Step 6: Run Server
python manage.py runserver
π Step 7: Output
π http://127.0.0.1:8000/layout/
β Output Features:
- Top navigation bar
- Responsive links
- Fixed footer
- Clean layout
π§ How It Works
Navbar
<div class="navbar">
π Contains navigation links
Footer
<div class="footer">
π Fixed at bottom
Responsive CSS
@media screen and (max-width: 600px)
π Adjusts layout for mobile
π₯ Key Concepts
| Component | Purpose |
|---|---|
| Navbar | Navigation |
| Footer | Information |
| CSS | Styling |
| Media Query | Responsiveness |
β οΈ Common Errors
β Forgot {% load static %}
π CSS will not apply
β Wrong CSS path
π Must be:
{% static 'css/style.css' %}
β Footer overlapping content
π Add spacing if needed
β Links not working
π Use {% url %} in real projects
π§ͺ Practice Questions
- Add logo in navbar
- Add dropdown menu
- Make sticky navbar
- Add social icons in footer
π€ Viva Questions & Answers
1. What is a navbar?
Navbar is a navigation bar used to access different pages.
2. What is footer?
Footer is the bottom section containing information like copyright.
3. What is responsive design?
Design that adjusts to different screen sizes.
4. What is media query?
CSS technique to apply styles based on screen size.
5. Why use external CSS?
For reusable and clean styling.
6. What is static file?
CSS, JS, images used for UI.
7. Can navbar be reused?
Yes, using template inheritance or include.
8. Why fix footer at bottom?
For consistent layout.
9. What is hover effect?
Style applied when mouse is over element.
10. Why is layout important?
Improves user experience and navigation.
π Next Post: Simple Portfolio Website
π Back to List: Django Programs (60 Questions with Solutions)
Further Reading
Introduction to Django Framework and its Features
Examples of Array Functions in PHP
Registration Form Using PDO in PHP
Inserting Information from Multiple CheckBox Selection in a Database Table in PHP
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
