Django

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


ComponentPurpose
NavbarNavigation
FooterInformation
CSSStyling
Media QueryResponsiveness

โš ๏ธ 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

  1. Add logo in navbar
  2. Add dropdown menu
  3. Make sticky navbar
  4. 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

Django Practice Exercise

Examples of Array Functions in PHP

Basic Programs in PHP

Registration Form Using PDO in PHP

Inserting Information from Multiple CheckBox Selection in a Database Table in PHP

programmingempire

princites.com

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *