Getting Started with Bootstrap

What is Bootstrap?

Benefits

Download

File Structure

bootstrap/
├── css/
│   ├── bootstrap.css
│   ├── bootstrap.css.map
│   ├── bootstrap.min.css
│   ├── bootstrap.min.css.map
│   ├── bootstrap-theme.css
│   ├── bootstrap-theme.css.map
│   ├── bootstrap-theme.min.css
│   └── bootstrap-theme.min.css.map
├── js/
│   ├── bootstrap.js
│   └── bootstrap.min.js
└── fonts/
    ├── glyphicons-halflings-regular.eot
    ├── glyphicons-halflings-regular.svg
    ├── glyphicons-halflings-regular.ttf
    ├── glyphicons-halflings-regular.woff
    └── glyphicons-halflings-regular.woff2

Getting started

Start by copying the HTML below to begin a minimal Bootstrap document

<!DOCTYPE html>
<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">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap Template</title>

    <!-- Bootstrap CSS-->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <h1>Hello, world!</h1>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <!-- Bootstrap JS-->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

Building HTML pages with Bootstrap

How to use Bootstrap components

Grids

<div class="container">
  <div class="row">
    <div class="col-md-8">
      Parent fixed-width column
      <div class="row">
        <div class="col-md-6">Nested column</div>
        <div class="col-md-6">Nested column</div>
      </div>
    </div>
  </div>
</div>
<div class="container-fluid">
  <div class="row">
    <div class="col-md-4">Fluid ..</div>
    <div class="col-md-4">.. and full-width ..</div>
    <div class="col-md-4">.. example</div>
  </div>
</div>

Typography

<p class="text-danger">Error: An error has been occurred while submitting your data.</p>

Forms

Images and Icons

Buttons, Button groups, Button dropdowns

<div class="btn-group">
  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
    Country <span class="caret"></span>
  </button>
  <ul class="dropdown-menu">
    <li><a href="#">Canada</a></li>
    <li><a href="#">Mexico</a></li>
    <li><a href="#">USA</a></li>
    <li role="separator" class="divider"></li>
    <li><a href="#">Nepal</a></li>
  </ul>
</div>

Customizing Bootstrap

Overriding With CSS

<!-- Replace bootstrap.min.css with custom css -->
<link rel="stylesheet" href="css/custom.css">
@import url("bootstrap.min.css");
.btn {
  -webkit-border-radius: 20px;
  -moz-border-radius: 20px;
  border-radius: 20px;
}

Generating A Custom Build

Overriding with LESS

For example:

.btn-large {
   padding: 9px 14px;
   font-size: @baseFontSize + 2px;
   line-height: normal;
   .border-radius(5px);
}

Installing LESS

  1. Install less using Node Package Manager (NPM)

npm install less

  1. Compile bootstrap.less

lessc bootstrap.less > bootstrap.css

For the minified version, use this instead:

lessc --compress bootstrap.less > bootstrap.min.css

Modularizing your changes

  1. Download Bootstrap source code, rename it to bootstrap and leave it untouched
  2. Create separate folder named custom
  3. Copy these files from bootstrap to custom folder and perform necessary modifications
    • custom-variables.less: Modify the variables in this copy instead of bootstrap original file
    • custom-other.less: Any other customizations that aren’t possible with the variables
    • custom-bootstrap.less: The new central file that you will compile to CSS
  4. Along with the original LESS files, imports the two custom files above using the following commands
@import "../bootstrap/less/bootstrap.less";
@import "custom-variables.less";
@import "custom-other.less";
@import "../bootstrap/less/utilities.less";

Resources:
- Tomislav Bacinger’s post from Toptol.com
- Thomas Park’s post from Smashing Magazine

comments powered by Disqus