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

Leave a Reply

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