๐ 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
