{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Bootstrap\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Bootstrap is a popular open-source CSS framework that developers use to build responsive and mobile-first websites efficiently. It was initially developed by Twitter.\n", "\n", "## Definition and Purpose of Bootstrap\n", "\n", "Bootstrap provides pre-made classes and components that developers can use to create modern and aesthetically pleasing web applications without starting from scratch. It includes a responsive grid system, pre-designed components such as buttons, navigation bars, modals, and more, as well as JavaScript plugins.\n", "\n", "By using Bootstrap, developers can ensure their websites are responsive, meaning they automatically adjust and look good on devices of all sizes, from smartphones to desktops. This responsiveness is a crucial aspect of web development in the age of mobile internet.\n", "\n", "## Overview of the Bootstrap Components\n", "\n", "Bootstrap comes with a broad array of pre-designed components, which include but are not limited to:\n", "\n", "- **Navigation Bar (Navbar):** A responsive horizontal bar that can contain links, text, and any other HTML element.\n", "\n", "- **Forms:** Pre-styled form controls such as input fields, checkboxes, and buttons.\n", "\n", "- **Buttons:** Pre-styled buttons with various sizes and colors.\n", "\n", "- **Cards:** A flexible and extensible content container with multiple variants and options.\n", "\n", "- **Modals:** Overlay popups for lightboxes, notifications, or custom content.\n", "\n", "- **Carousels:** A slideshow component for cycling through elements, like a carousel.\n", "\n", "- **Alerts:** Provide contextual feedback messages for typical user actions with a handful of available and flexible alert messages.\n", "\n", "These components can significantly speed up development time and ensure consistency across different parts of a web application.\n", "\n", "In the following sections, we will explore how to integrate and use Bootstrap within a Flask application to achieve fast and responsive web development.\n", "\n", "## Setting Up Bootstrap in a Flask Project\n", "\n", "Bootstrap can be added to a Flask project in two primary ways. You can either download and link the Bootstrap CSS and JavaScript files directly in your HTML templates, or you can use the Flask-Bootstrap extension that integrates Bootstrap with your Flask application seamlessly.\n", "\n", "### Downloading and Linking Bootstrap CSS and JavaScript Files\n", "\n", "You can download the Bootstrap source files from the official [Bootstrap website](https://getbootstrap.com/). Once downloaded, you can include the Bootstrap CSS and JavaScript files in your HTML templates:\n", "\n", "```html\n", "\n", "\n", "
\n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", "```\n", "\n", "### Using Flask-Bootstrap Extension\n", "\n", "Another way to add Bootstrap to your Flask application is by using the Flask-Bootstrap extension. This extension simplifies the process of integrating Bootstrap into your Flask application. To install Flask-Bootstrap, use pip:\n", "\n", "```bash\n", "pip install flask-bootstrap\n", "```\n", "\n", "After installing the extension, you can initialize it in your Flask application:\n", "\n", "```python\n", "from flask_bootstrap import Bootstrap\n", "\n", "app = Flask(__name__)\n", "bootstrap = Bootstrap(app)\n", "```\n", "\n", "With Flask-Bootstrap initialized, you can use the `{% extends \"bootstrap/base.html\" %}` in your templates to inherit from a base template that includes all the necessary Bootstrap files.\n", "\n", "## Understanding Bootstrap Grid System\n", "\n", "Bootstrap uses a grid system for designing layouts. It uses rows, columns, and containers to layout and align content. It's built with flexbox and is fully responsive.\n", "\n", "### Explanation of the Grid System\n", "\n", "The grid system consists of containers, rows, and up to 12 columns. Here's how it works:\n", "\n", "- **Containers:** Containers are the most basic layout element in Bootstrap and are required when using the grid system.\n", "\n", "- **Rows:** Rows are wrappers for columns. Each row aligns a set of columns that should appear as a horizontal group.\n", "\n", "- **Columns:** Columns are the immediate child of rows. The number of columns in a row should not exceed 12.\n", "\n", "### Rows, Columns, and Responsive Design\n", "\n", "The Bootstrap grid system allows you to specify different column widths for different screen sizes. This makes it easy to create a responsive design. For example:\n", "\n", "```html\n", "Some quick example text to build on the card title and make up the bulk of the card's content.
\n", " Go somewhere\n", "