Create a Bootstrap Styled Responsive Page

πŸ“Œ Introduction

Bootstrap is a CSS framework used to create:

  • Responsive layouts
  • Attractive UI
  • Mobile-friendly designs

πŸ‘‰ No need to write full CSS manually.


🎯 Program Statement

πŸ‘‰ Create a Bootstrap styled responsive page.


🧠 Why Bootstrap?

  • Fast UI development
  • Mobile responsive
  • Predefined components

βš™οΈ Step 1: Create View


πŸ“ File: views.py

πŸ”Ή Path:

myproject/myapp/views.py

πŸ”Ή Code:

from django.shortcuts import render

def bootstrap_demo(request):
return render(request, 'bootstrap.html')

βš™οΈ Step 2: 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('bootstrap/', views.bootstrap_demo),
]

βš™οΈ Step 3: Create Template


πŸ“ File: bootstrap.html

πŸ”Ή Path:

myproject/templates/bootstrap.html

πŸ”Ή Code:

<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Page</title>

<!-- Bootstrap CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container mt-4">

<h1 class="text-center text-primary">Bootstrap Responsive Page</h1>

<!-- Row -->
<div class="row mt-4">

<!-- Column 1 -->
<div class="col-md-4">
<div class="card p-3">
<h3>Card 1</h3>
<p>This is a Bootstrap card.</p>
</div>
</div>

<!-- Column 2 -->
<div class="col-md-4">
<div class="card p-3">
<h3>Card 2</h3>
<p>Responsive layout example.</p>
</div>
</div>

<!-- Column 3 -->
<div class="col-md-4">
<div class="card p-3">
<h3>Card 3</h3>
<p>Works on mobile & desktop.</p>
</div>
</div>

</div>

<!-- Button -->
<div class="text-center mt-4">
<button class="btn btn-success">Click Me</button>
</div>

</div>

</body>
</html>

βš™οΈ Step 4: Run Server

python manage.py runserver

🌐 Step 5: Output

πŸ‘‰ http://127.0.0.1:8000/bootstrap/


βœ… Output Features:

  • Centered heading
  • 3 responsive cards
  • Styled button
  • Mobile-friendly layout

🧠 How It Works


Bootstrap CDN

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">

πŸ‘‰ Loads Bootstrap


Grid System

<div class="row">
<div class="col-md-4">

πŸ‘‰ Creates responsive columns


Card Component

<div class="card p-3">

πŸ‘‰ Styled content box


Button

<button class="btn btn-success">

πŸ‘‰ Pre-styled button


πŸ”₯ Key Concepts


ClassPurpose
containerPage layout
rowHorizontal grouping
col-md-4Column size
cardContent box
btnButton styling

⚠️ Common Errors


❌ Bootstrap CDN missing

πŸ‘‰ Page will look plain


❌ Wrong class name

❌ Wrong:

col-4

βœ… Correct:

col-md-4

❌ Not using container

πŸ‘‰ Layout breaks


πŸ§ͺ Practice Questions

  1. Add 4 cards instead of 3
  2. Change button color
  3. Add image inside card
  4. Create form using Bootstrap

🎀 Viva Questions & Answers


1. What is Bootstrap?

Bootstrap is a CSS framework for designing responsive web pages.


2. What is CDN?

Content Delivery Network used to load external libraries.


3. What is responsive design?

Design that adapts to different screen sizes.


4. What is grid system?

Bootstrap layout system using rows and columns.


5. What is container class?

It provides proper spacing and alignment.


6. What is card component?

A styled box used to display content.


7. What is col-md-4?

Defines column width for medium screens.


8. What is Bootstrap button class?

btn, btn-primary, btn-success, etc.


9. Why use Bootstrap?

To quickly build responsive UI.


10. Is Bootstrap mobile-friendly?

Yes, it is fully responsive.


πŸ”— Navigation

πŸ‘‰ Next Post: Responsive Navbar and Footer
πŸ‘‰ 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 *