Popular Science Post: What is Bootstrap? Getting started with the Bootstrap development framework

Bootstrap is a free and open source web development framework. It aims to simplify the web development process of responsive, mobile-first websites by providing a set of syntax for template design.

In other words, Bootstrap helps web developers build websites faster because they don’t need to worry about basic commands and functionality. It consists of HTML, CSS, and JS-based scripts for various web design-related features and components.

This article will introduce the benefits of using Bootstrap and explain the different file types it uses. By the end, you'll know if Bootstrap can benefit your workflow.

Basic functions of Bootstrap

Bootstrap official website

The main goal of Bootstrap is to create responsive, mobile-first websites. It ensures that all interface elements of the website work optimally on all screen sizes.

Bootstrap comes in two variants - precompiled and source-based versions . Experienced developers prefer the latter because it lets them customize the styling to fit their projects.

For example, the "source" version of Bootstrap gives you access to the Sass port . This means it creates a custom stylesheet imported into Bootstrap, allowing you to modify and extend the tool as needed.

You can also install Bootstrap using a package manager , a tool for managing and updating frameworks, libraries, and assets.

Some of the most popular package managers include npm , Composer , and Bower . Npm manages server-side dependencies, while Composer focuses on the front-end. If you work on PHP-based projects, consider using Bower instead .

Due to its popularity, more and more Bootstrap communities have emerged. These are great places for web developers and web designers to share knowledge and discuss patches for the latest versions of Bootstrap.

Why use Bootstrap?

Some of Bootstrap's interface components include navigation bars, grid systems, image carousels, and buttons.

If you're still not sure whether Bootstrap is worth a try, here are the advantages of using it compared to other web development frameworks.

Easy to use

First, Bootstrap is easy to learn. Due to its popularity, there are plenty of tutorials and online forums to help you get started.

One of the reasons why Bootstrap is so popular among web developers and web designers is that it has a simple file structure. Its files are compiled for easy access, and only basic knowledge of HTML, CSS, and JS is required to modify them.

You can also use themes from popular content management systems as learning tools. For example, most WordPress themes are developed using Bootstrap and are accessible to any beginner web developer.

To increase your website’s page load time, Bootstrap minifies CSS and JavaScript files. Additionally, Bootstrap maintains syntax consistency across websites and developers, making it ideal for team-based projects.

responsive grid

Bootstrap comes with a predefined grid system, saving you from creating one from scratch. The grid system consists of rows and columns, allowing you to create a grid within an existing grid instead of entering media queries in a CSS file.

Additionally, Bootstrap’s grid system makes the data entry process more straightforward. It contains a large number of media queries that allow you to define custom breakpoints for each column according to your web project needs.

The default settings are usually more than adequate. After creating the grid, you just add content to the container.

The Bootstrap grid system has two container classes to better suit desktop and mobile projects - a fixed container ( .container ) and a fluid container ( .container-fluid ).

The first container class provides a fixed-width container, while the latter provides a full-width container with the ability to resize your item to all screen sizes.

Browser compatibility

Accessing your website through different browsers can help reduce bounce rates and rank higher in search results. Bootstrap fulfills this requirement by being compatible with the latest versions of popular browsers.

Although lesser-known browsers like WebKit and Gecko are not supported, websites with Bootstrap should run fine on them as well. However, modal and drop-down menus may have limitations on small screens.

Bootstrap graphics system

Bootstrap handles image display and responsiveness using its predefined HTML and CSS rules.

Adding the .img-responsive class will automatically resize the image based on the user's screen size. This will benefit your website's performance since reducing image size is part of the website optimization process.

Bootstrap also provides additional classes like .img-circle and .img-rounded, which help in modifying the shape of the image.

Bootstrap documentation

Bootstrap provides documentation for developers who want to learn to use the framework for the first time. You can find the following topics on the Bootstrap documentation page :

  • Contents ‒ Covers precompiled Bootstrap source code.
  • Browsers and Devices ‒ Lists all supported web and mobile browsers and mobile-based components.
  • JavaScript  ‒ Break down various JS plugins built on jQuery.
  • Themes – Interpret built-in Sass variables for easy customization.
  • Tools‒ teaches you how to use Bootstrap’s npm scripts to perform various operations.
  • Accessibility ‒ Covers Bootstrap’s capabilities and limitations around structural markup, components, color contrast, content visibility, and transition effects.

The documentation also includes code examples for basic practices. You can even copy and modify code examples for your projects, saving you time writing code from scratch.

Why you shouldn't use Bootstrap

Despite its advantages, Bootstrap has certain limitations and is not suitable for certain types of projects.

Since Bootstrap has a consistent visual style, it requires a lot of customization and style overrides to make one project different from another. Otherwise, all websites built using this framework will have the same navigation, structure, and design components, making them look unprofessional.

Having a lot of features means including large files.  If you're not careful, using Bootstrap in your project can slow down your website's loading time and tax your server. To avoid this problem, make sure to only add the classes you need and use minified versions of the files.

While Bootstrap is compatible with the latest versions of popular browsers, this is not the case with older versions. This means that the appearance of your website will depend entirely on how hard your users try to update their browsers.

Another drawback is that Bootstrap styles are relatively clunky. This results in unnecessary HTML output and wastes CPU resources.

Although it's easy to use, Bootstrap has a bit of a learning curve at first  . Learning the available classes and components takes time and can be complex for people without technical knowledge.

3 Bootstrap main files

Bootstrap consists of a set of syntax compiled in three main files - Bootstrap.css , Bootstrap.js and Glyphicons . Keep in mind that Bootstrap requires a JS library called jQuery to run JS plugins and components.

Below are the three main framework files that govern the user interface and functionality of the website.

Bootstrap.css

Bootstrap.css is a CSS framework used to arrange and manage the layout of a website. HTML handles the content and structure of a web page, while CSS handles the layout itself. For this reason, both structures need to coexist in order to perform a specific operation.

Bootstrap.css and its features help developers create a unified look and feel across as many pages as desired. Therefore, web developers don't have to spend hours manually editing.

No need to code from scratch, you just need to reference the web page to a CSS file. Any necessary changes can be done in this file alone.

CSS functions are not limited to text styles, as you can use them to format other aspects in your website, such as table and image layout.

Since CSS has a lot of declarations and selectors, it can take some time to remember them all. See our CSS Cheat Sheet to simplify your learning process.

Bootstrap.js

This file is the core part of Bootstrap. It consists of JavaScript files that are responsible for the interactivity of the website.

To save time writing JavaScript syntax multiple times, developers tend to use jQuery - a popular open source cross-platform JavaScript library.

Here are a few examples of what jQuery can do:

  • Perform AJAX requests, such as dynamically subtracting data from another location.
  • Create widgets using a collection of JavaScript plugins.
  • Create custom animations using CSS properties.
  • Add dynamics to website content.

While Bootstrap with CSS properties and HTML elements works fine, it requires jQuery to create a responsive design. Otherwise, you're stuck with the bare, static parts of the stylesheet language.

Therefore, every software engineer should know about jQuery as it is an important part of web development.

Glyphicons

Icons are an integral part of the website front-end as they often display actions and data in the user interface.

Bootstrap uses icons called Glyphicons, which includes the Glyphicons Halflings set . Although the design is basic, they perform their basic functions and are free to use.

If you want to find more stylish icons, Glyphicons sells a variety of premium packages for niche-specific websites.

You can also download individual and theme-specific icons for free on various websites such as Flaticon , GlyphSearch , and Icons8 .

To change the size of Glyphicons, you need to  override the default style using the CSS font-size property.

How to use Bootstrap in web development

To better understand how to use bootstrap, take a look at the example below.

<html lang="en">

<head>

<meta charset="utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>Bootstrap 101 Template</title>

<link href="css/bootstrap.min.css" rel="stylesheet" />

</head>

<body>

<h1>Hello, world!</h1>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script src="js/bootstrap.min.js"></script>

</body>

</html>

We will explain some of these lines in more detail.

meta charset="utf-8"

Specifies the character set used to write the website. In this case, UTF-8 refers to Unicode.

meta http-equiv="X-UA-Compatible"

Determines the version of Internet Explorer that should render the page. With Edge mode, it's set to use the highest mode available.

meta name="viewport"

Make sure the page to viewport size ratio is 1:1.

link href="css/bootstrap.min.css" rel="stylesheet"

This is where we add Bootstrap core CSS.

src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"

Load jQuery via Google CDN. It's best to load it from a CDN via HTTP as the files can be cached for up to a year.

src="js/bootstrap.min.js

Added Bootstrap core JavaScript. This syntax must be lower than jQuery syntax to function properly. The addition process can be done via Google's URL or manual download.

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>

Bootstrap provides a JavaScript package to simplify this process. However, bootstrap.bundle.js and bootstrap.bundle.min.js contain Popper instead of jQuery. Popper is a positioning engine used to calculate the positioning of elements.

<nav class="navbar navbar-expand-lg navbar-light bg-light">

<a class="navbar-brand" href="#">Navbar</a>

<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">

<span class="navbar-toggler-icon"></span>

</button>

<div class="collapse navbar-collapse" id="navbarNavAltMarkup">

<div class="navbar-nav">

<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>

<a class="nav-item nav-link" href="#">Features</a>

<a class="nav-item nav-link" href="#">Pricing</a>

<a class="nav-item nav-link disabled" href="#">Disabled</a>

</div>

</div>

</nav>

Example of how to create a site menu using Bootstrap navigation links.

summary

Bootstrap is a free front-end framework that is popular among developers today, especially those working in the field of web design. It is easy to use and saves developers a lot of time manually coding HTML, CSS and JavaScript.

The Bootstrap framework is flexible and robust enough to meet almost all needs of front-end website development. Its best feature is designing templates so that web pages work optimally on all screen sizes.

Although there's a bit of a learning curve, it offers plenty of resources to help you get started. Some of the best learning platforms include Bootstrap documentation pages and IT-focused forums like Stack Overflow .

Guess you like

Origin blog.csdn.net/weixin_44026962/article/details/135341714