Assignments Of Class 28: CSS Frameworks Introduction
Assignment 1: Create a Responsive Navigation Bar using Bootstrap
Objective:
Design a responsive navigation bar using Bootstrap that adjusts itself based on the screen size.
Instructions:
- Create a navigation bar with the following items: Home, About, Services, Contact.
- The navbar should be responsive and collapse into a hamburger menu on mobile devices.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Navbar</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">My Website</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Explanation:
- We used navbar-expand-lg to make the navbar collapse into a hamburger menu on smaller screens (less than 992px wide).
- The navbar-toggler button is used to toggle the collapsed navbar on smaller screens.
- The ml-auto class ensures the navbar items are aligned to the right.
Output:
The navigation bar will be displayed, and on smaller screens, the navbar links will collapse into a hamburger menu.
Assignment 2: Create a Grid Layout with Bootstrap
Objective:
Create a responsive grid layout using Bootstrap that consists of 3 columns.
Instructions:
- Create a 3-column layout.
- The columns should stack on top of each other on smaller screen sizes (below 768px).
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grid Layout</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="p-3 border bg-light">Column 1</div>
</div>
<div class="col-md-4">
<div class="p-3 border bg-light">Column 2</div>
</div>
<div class="col-md-4">
<div class="p-3 border bg-light">Column 3</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Explanation:
- The col-md-4 class defines a column that takes up 4 out of 12 available grid columns, making 3 equal-width columns in the row.
- On small screens, the columns will stack vertically because Bootstrap's grid system is mobile-first.
Output:
- On large screens, the content will be displayed in three columns.
- On smaller screens, the columns will stack vertically.
Class 28: CSS Frameworks Introduction
Objective:
- Introduce students to popular CSS frameworks such as Bootstrap and Tailwind CSS.
- Learn how to use these frameworks to streamline the development process by utilizing pre-built components and utilities.
Topics:
1. Bootstrap Overview:
o What is Bootstrap?
o Key features of Bootstrap (grid system, responsive design, pre-built components).
o How to include Bootstrap in a project (CDN, downloading files).
o Understanding the Bootstrap grid system (container, row, and column classes).
o Commonly used Bootstrap components (buttons, navbars, cards, forms, etc.).
2. Tailwind CSS Overview:
o What is Tailwind CSS?
o Key features of Tailwind (utility-first design, flexibility, customizability).
o How to include Tailwind in a project (via CDN or using npm).
o Basic concepts: utility classes, responsiveness, and customization.
o Comparison between Bootstrap and Tailwind CSS.
Lab Exercise:
- Use Bootstrap classes to style a webpage.
- Create a simple webpage with a navigation bar, a hero section, a product section, and a footer using Bootstrap classes.
Assignments:
Assignment 1: Basic Webpage with Bootstrap
Problem:
Create a basic webpage that includes a header, a main content section with a paragraph, and a footer. Use Bootstrap to style these elements.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic Webpage</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<header class="bg-primary text-white p-4">
<h1>Welcome to My Website</h1>
</header>
<main class="container my-5">
<p>This is a simple webpage styled using Bootstrap.</p>
</main>
<footer class="bg-dark text-white text-center p-3">
<p>© 2025 My Website</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Explanation:
- Bootstrap CDN is used for styling.
- bg-primary and bg-dark classes add background colors.
- text-white ensures the text is white on colored backgrounds.
- container adds padding and centers content.
- p-4 and p-3 are padding classes.
Output: A simple webpage with a header, paragraph, and footer, all styled with Bootstrap.
Assignment 2: Bootstrap Grid Layout
Problem:
Create a two-column layout using Bootstrap’s grid system. One column should contain an image, and the other should contain text.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Two Column Layout</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container my-5">
<div class="row">
<div class="col-md-6">
<img src="https://via.placeholder.com/500" class="img-fluid" alt="Placeholder Image">
</div>
<div class="col-md-6">
<h2>Welcome to the Bootstrap Grid Layout</h2>
<p>This is a two-column layout created using Bootstrap’s grid system.</p>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Explanation:
- col-md-6 creates two columns, each taking up 50% of the screen width on medium-sized devices and above.
- img-fluid makes the image responsive, scaling it to fit the container.
Output: A webpage with a responsive two-column layout.
Assignment 3: Navbar with Bootstrap
Problem:
Create a navigation bar using Bootstrap with links to 'Home', 'About', and 'Contact' sections.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Navbar Example</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">My Website</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Explanation:
- navbar class creates the navigation bar.
- navbar-expand-lg makes the navbar responsive.
- navbar-toggler and collapse are used for collapsing the navbar on smaller screens.
Output: A responsive navigation bar with links to 'Home', 'About', and 'Contact'.
Assignment 4: Tailwind CSS Utility Classes
Problem:
Create a webpage using Tailwind CSS to display a header, a content section with text, and a footer. Style the elements using utility classes.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tailwind Webpage</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 text-gray-800">
<header class="bg-blue-500 text-white p-5">
<h1 class="text-3xl">Welcome to My Website</h1>
</header>
<main class="container mx-auto my-10 p-5 bg-white shadow-lg">
<h2 class="text-2xl font-semibold">About This Webpage</h2>
<p>This webpage is styled using Tailwind CSS utility classes.</p>
</main>
<footer class="bg-blue-500 text-white p-3 text-center">
<p>© 2025 My Website</p>
</footer>
</body>
</html>
Explanation:
- Tailwind utility classes are used to style elements.
- bg-blue-500 sets the background color.
- text-white makes the text white.
- p-5 and p-3 set padding, while mx-auto centers the content.
Output: A webpage styled with Tailwind CSS.
Assignment 5: Tailwind CSS Flexbox Layout
Problem:
Create a flexbox layout using Tailwind CSS with two items aligned horizontally.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tailwind Flexbox</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-200">
<div class="flex justify-between p-5">
<div class="bg-blue-500 text-white p-5">Item 1</div>
<div class="bg-green-500 text-white p-5">Item 2</div>
</div>
</body>
</html>
Explanation:
- flex creates a flex container.
- justify-between spaces items evenly.
- bg-blue-500 and bg-green-500 provide background colors.
Output: Two items placed horizontally with space between them using Flexbox.
Assignment 6: Tailwind CSS Card Layout
Problem:
Create a card layout with an image, title, and description using Tailwind CSS.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tailwind Card</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<div class="max-w-sm mx-auto bg-white shadow-lg rounded-lg p-5">
<img src="https://via.placeholder.com/300" alt="Card Image" class="w-full rounded-lg">
<h2 class="text-xl font-semibold mt-3">Card Title</h2>
<p class="text-gray-700">This is a card description. It provides brief information about the content of the card.</p>
</div>
</body>
</html>
Explanation:
- max-w-sm limits the card’s width.
- bg-white, shadow-lg, and rounded-lg give the card its appearance.
- mt-3 adds margin-top to the title.
Output: A card with an image, title, and description.
Assignment 7: Responsive Grid with Tailwind
Problem:
Create a responsive grid layout using Tailwind CSS. The grid should have three columns on large screens and one column on small screens.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Grid</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-200">
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 p-5">
<div class="bg-blue-500 text-white p-5">Item 1</div>
<div class="bg-green-500 text-white p-5">Item 2</div>
<div class="bg-red-500 text-white p-5">Item 3</div>
</div>
</body>
</html>
Explanation:
- grid-cols-1, sm:grid-cols-2, and lg:grid-cols-3 define the number of columns for different screen sizes.
- gap-4 adds spacing between the items.
Output: A responsive grid that adjusts the number of columns based on screen size.
Assignment 8: Tailwind Button Styling
Problem:
Create buttons with different styles using Tailwind CSS (primary, secondary, and disabled).
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Button Styles</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<button class="bg-blue-500 text-white p-3 rounded-lg hover:bg-blue-700">Primary Button</button>
<button class="bg-gray-500 text-white p-3 rounded-lg hover:bg-gray-700 mt-4">Secondary Button</button>
<button class="bg-gray-300 text-white p-3 rounded-lg mt-4 cursor-not-allowed" disabled>Disabled Button</button>
</body>
</html>
Explanation:
- bg-blue-500 and bg-gray-500 set background colors for primary and secondary buttons.
- hover:bg-blue-700 and hover:bg-gray-700 add hover effects.
- cursor-not-allowed disables the button.
Output: Three buttons styled with different states.
Assignment 9: Tailwind Typography Styling
Problem:
Style a paragraph with Tailwind CSS typography classes for better readability.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Typography Styling</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<p class="text-lg font-serif text-gray-800 leading-relaxed max-w-prose mx-auto p-5">
This is a paragraph styled with Tailwind CSS. Notice how the typography looks clean and readable with larger text, a comfortable line height, and proper spacing.
</p>
</body>
</html>
Explanation:
- text-lg increases font size.
- font-serif uses a serif font.
- leading-relaxed adjusts line height for better readability.
- max-w-prose limits the paragraph width.
Output: A well-styled paragraph with improved readability.
Assignment 10: Tailwind Responsive Text
Problem:
Create a responsive text that changes size based on screen width.
Solution:
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Text</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<h1 class="text-2xl sm:text-3xl lg:text-4xl xl:text-5xl font-bold text-center p-5">
Responsive Text Example
</h1>
</body>
</html>
Explanation:
- text-2xl, sm:text-3xl, lg:text-4xl, and xl:text-5xl define different text sizes for different screen sizes.
Output: A heading that adjusts its text size based on the screen width.
No comments:
Post a Comment