Comprehensive Bootstrap Guide
Comprehensive Bootstrap Guide
SUMMARY
Summary...................................................................................................................................... 1
Bootstrap ...................................................................................................................................... 4
Bootstrap at full speed
What is that
Download
Installation .............................................................................................................................................................. 4
Usage
CSS classes to style your site
A layout grid (that we place in a container)................................................................................... 5
Complete templates for layout
Complete Bootstrap tutorial: consult it without moderation !!!..................................................................................... 5
Introduction
Prerequisites
CSS frameworks ..................................................................................................................................... 6
Usage ................................................................................................................................................... 6
Advantages ................................................................................................................................................... 6
Cross-browser : [Link]
Cross-device: design responsive
Speed................................................................................................................................................................... 6
Disadvantages ............................................................................................................................................. 6
Adapter Bootstrap : LESS............................................................................................................................ 7
Resources.................................................................................................................................................. 7
Official resources .............................................................................................................................................. 7
Tutorial
Testing, learning and/or development tool ........................................................................................ 7
Use by CDN..................................................................................................................................8
CDN: what is it?
CDN of the css file: bootsrapcdn
CDN of js files: google and bootstrapcdn................................................................................................. 8
Example
Installation on your machine: tutorial ............................................................................................................9
Utility: alternative to the CDN
Download Bootstrap
Minimum 9
Advanced
Download content....................................................................................................................... 9
Minimum 9
With sources ........................................................................................................................................................... 9
Contents of the dist folder.............................................................................................................................. 9
Subfolder css
Subfolder fonts
Subfolder js
Download the jQuery plugin
Installation of the bootstrap directory at the root
Production environment.............................................................................................................................. 10
Development Environment
Look at the bootstrap class code ............................................................... 10
What's that?
• CSS framework, styled and responsive.
• Created by the developers of Twitter
• Based on HTML 5 and CSS3.
• Quality JQuery plugins shipment
• Features a simple and effective grid system to organize the visual layout of a page
web
• Add style to buttons, forms, navigation...
• Propose layout templates
• Allows you to design a website quickly and with few lines of added code.
Download
Download Bootstrap:[Link]
JQuery plugins are not installed by default in Bootstrap. They can be retrieved here:
[Link] the plugins in the js folder.
Installation
Install the bootstrap folder with its 3 folders css, fonts, and js at the root of the site.
Usage
To use bootstrap in an HTML file:
<script
src="[Link]
.[Link]"></script>
Ø etc.
Prerequisites
HTML-CSS
CSS frameworks
There are many of them: Elasticss, Knacss, Blueprint, unsemantic, YUI, 52Framework, BlueTrip,
ez-css, Pure, Gumby, etc.
Foundation: very advanced
Bootstrap: very advanced and very popular
Usage
• Simple: it is used by linking a file containing the classes defined by bootstrap.
• Then we can add these classes to the HTML tags to achieve styled results and
responsive.
• Bootstrap offers good [Link] translatable text found in the provided URL.
• There are many resources on the web:The given text is a URL and does not require translation.
• Bootstrap ensures continuous evolution.
Advantages
Cross-browser: [Link]
Abstraction of browsers that will all react the same way thanks to [Link]: small CSS file
who establishes rules to have the same rendering regardless of the browser used.
Speed
Allows for quickly designing a stylish website: pre-existing structures, homogeneous style,
positioning grid (12 columns in Bootstrap), styled elements (button, bar)
navigation, …), etc.
Disadvantages
Training time: very quick for Bootstrap
Normalization of graphics: all sites look the same!
But Bootstrap is configurable with LESS.
Based on HTML-4. With the development of HTML-5, the Bootstrap syntax becomes cumbersome.
Resources
Official resources
Site :[Link]
Blog :[Link]
Github :Invalid input for translation. Please provide text to translate.
Tutorial
The provided text is a URL and cannot be translated.
[Link]
Unable to access or translate content from external links.
Unable to translate a URL. Please provide text for translation.
<script
src="[Link]
.[Link]"></script>
Example
The provided text is a URL and does not contain any translatable content.
Download Bootstrap
[Link]
Minimum
• allows you to retrieve the files necessary for operation
Bootstrap. It's enough to use bootstrap.
Advanced
• allows you to retrieve all the source files as well.
• it is a port of Bootstrap in Sass for project users who
use Sass (Rails, Compass...).
Download content
Minimum
If we only download Bootstrap:
we get a directory "dist" with 3 subdirectories:
• dist/css
• dist/fonts
• dist/js.
With sources
If you download the sources: you have a folder with several files and folders. The only folder
the dist folder is useful.
Subfolder css
It contains the following files:
• [Link]: it includes the basic classes of Bootstrap
• [Link]: it contains specific style rules to create a theme
specific for Bootstrap
• The min versions are the production versions: the code is on one line so as not to
take up all the space. Non-min versions allow browsing through the code.
Subfolder fonts
The directory contains icons in different formats: svg, ttf, woff, eot
[Link]
[Link]
Subfolder js
• It contains the files [Link] and [Link] which are only useful if we use jQuery plugins.
• [Link] contains the JavaScript code for Bootstrap components.
• The versions are the production versions: the code is on one line so as not to take up
the whole place.
Production environment
We only need: css/[Link], the fonts folder, js/[Link],
js/[Link]
Development environment
We add css/[Link], the fonts folder, js/[Link], js/[Link] in order to be able to consult.
the source files.
Autonomous loading
Ø CSS file
<head>
…
<link href="bootstrap/css/[Link]" rel="stylesheet">
</head>
Ø js files
The JavaScript files will load as follows:
<script src="bootstrap/js/[Link]"></script>
<script src="bootstrap/js/[Link]"></script>
<head>
Principles
Link the bootstrap file.
Specific cases:
• IE
• Mobile
• IE < 9
Example: 00_loadBS.html
Principles:
The page displays a simple Hello World.
She links the [Link] file in the <head>.
She links
<head>
Bootstrap template
<meta charset="utf-8">
<!-- bootstrap link: -->
<link href="../bootstrap/css/[Link]"
rel="stylesheet">
for mobiles:
<meta name="viewport" content="width=device-width, initial-
<script
src="[Link]
<![endif]-->
</head>
<script>
2 files to load for JavaScript:
• the bootstrap file
• a Google jQuery API
In a <script> tag, just before the </body>, we include references to the .js files:
Elements
Presentation
Unable to access the content of the provided link. Please provide the text you want translated.
[Link]
The grid is a division of the page into 12 columns that all have the same width.
The width of the columns adjusts to the width of the window.
For the lines, the size adjusts to what we put inside. It's classic HTML: the height
The function of a cell will depend on what we put inside it.
Here in columns 3, 6, and 11, the height of the block adapts to the text.
Line
class=row
Columns
class=col-XX-*
XX: xs, sm, md or lg. These are the formats that modify behavior.
from 1 to 12
examples :
col-xs-1 for a 1 column element
col-md-8 for an element of 8 columns
Ø Principles
The grid must be contained within a container or container-fluid.
2. container and container-fluid are blocks for grouping tags.
3. The container leaves a margin on the right and left.
The fluid container stretches across the entire window.
Examples
[Link]
[Link]
[Link]
[Link]
Example: 01_1_grid.html
Ø Display
Here we display a block of 4 and a block of 8.
The block of 4 contains a lot of text.
Ø Test
[Link]
Ø HTML
<div class="container-fluid">
<div class="col-xs-4">
<p>
Block of 4
Bla bla bla
</p>
<div class="col-xs-8">
Block of 8
</p>
</div>
Ø HTML Structure
A "container-fluid" div that contains our bootstrap blocks.
A div for the line: row
In the line: one div per column: one column of 4 and one column of 8.
Ø CSS
.row { /* all rows */
text-align: center;
line-height: 40px; /* line height */
}
Example: 02_2_grid_float.html
Ø Display
We display a block of 4 and a block of 6. There are 2 columns left that are not in a block.
You can put text in these two columns: it is on the line (in the 'row' div)
If we put a lot of text, we see that the blocks are handled like 'floats': the text that we ...
surround the previous blocks.
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
Ø Test
[Link]
Principles
The formats of the columns define behavior based on screen size.
The blocks will stack or not depending on the screen size and the xs, sm, md, or lg format.
The choice of format defines the 'stacked if size < format'.
• col-xs-*: x small (smartphone): always aligned
• col-sm-*: small (tablet): aligned if >=768px, stacked otherwise (stacked if smartphone).
• col-md-* : medium (laptop) : aligned if >=992px, stacked otherwise (stacked if
. tablet)
• col-lg-*: large (fixed screen): aligned if >=1200px, stacked otherwise (stacked if mobile).
Example: 02_stacking_grid.html
Ø Principles
We present four rows with two columns in each row: of 4 and of 8.
These columns will be xs, sm, md, or lg.
Their behavior will therefore be different depending on the size of the screen.
The lg columns are the first to stack when the screen decreases.
The xs columns will never stack.
Note that when stacking, the two blocks (of 4 and 8) have the same width.
Ø Test
[Link]
ml
Ø HTML
<div class="container-fluid">
<div class="row">
Width xs 4
Width xs 8 - always aligned
<div class="row">
Width sm 4
Width sm 8 - aligned if >= 768
px</div>
<div class="row">
Width lg 4
Width lg 8 - aligned if >=1200 px
8
<script>
function myFunction() {
Width of the
window:
}
Ø CSS
.row{ /* all rows */
text-align: center;
line-height: 40px; /* line height */
}
[class*="-4"] { /* all attributes class = to %-4% */
background-color: aqua;
}
[class*="-8"] { /* all class attributes = to %-8% */
background-color: pink;
}
[class*="col-"] { /* all class attributes = to %col-% */ }
border: 1px solid black;
border-radius: 6px; /* rounded corners */
}
Ø JavaScript Note
We define a JavaScript function that displays the screen width in pixels and the screen type.
(smartphone, tablet, laptop, desktop computer)
This function updates the HTML page with an 'innerHTML' (DOM management).
It is called by an 'onload' and an 'onresize' in the <body> (event handling).
Ø Remark
The two columns must have the same format (lg in col-lg-4 and col-lg-8 for example)
Otherwise, we get strange behavior.
Ø Example: 03_complex_grid.html
[Link]
<div class="row">
1 col
2 columns
3 columns
6 columns
<div class="row">
12 columns
<div class="row">
4 columns
8 columns
</div>
Ø Syntax
class="col-XX-offset-*"
Ø Example: 04_grid_with_holes.html
[Link]
<div class="row">
3 columns
6 columns
3 columns
<div class="row">
3 columns
3 columns
Ø Principles
A first line independent of 12 columns
A second line with 8 and 4 columns
In the block of 8 columns, a 3-row layout with 4 columns and 6 columns with an offset of 2.
th
In this block of 6 columns, a 4th row with 3 columns and an offset of 1, 5 columns and an offset.
th
of 1
Ø Test
[Link]
Ø Syntax
class="col-XX-push-*": shift to the right, from its "normal" position
class="col-XX-pull-*": shift to the left, from its "normal" position
It should be noted that the behavior is complex to analyze due to a shift from the position.
normal.
Ø Example: 06_shifted_grid.html
Principles
Column 1 is pushed to the right by 8 from 0 (from the edge)
Column 2 is pushed to the right by 3 from its 'normal' position which would be just after
column 1 if it had not been pushed: so, starting from 2: it starts at 5.
Column 3 is pushed to the left by 2 from its 'normal' position which would be just after
column 2 if column 1 and 2 had not been pushed: so from 4: it starts in 2
Ø Test
[Link]
Ø Code
<div class="row">
Column 1
Column 2
Column 3
Classic layout
Principles
The header is a row on 12 columns. The same goes for the footer.
A row is defined that will contain the menu (nav) in 2 columns, and the section in 10.
columns.
In the section, a line is defined that contains the article over 10 columns, and div for the asides.
of 2 columns.
In the div of the asides, we place the aside, on 12 columns each.
For the footer, we choose not to put a line, but to place it over 12 columns.
Test
The provided text is a URL and does not contain translatable content.
[Link]
Code
row
<div class="col-lg-12">
Header
</div>
</header>
<div class="row">
<nav class="col-sm-2">
Menu
</nav>
<section class="col-sm-10">
Section
<div class="row">
<article class="col-sm-10">
Article
translatedText
</section>
<footer class="col-lg-12">
Footer
</footer></footer>
Test
[Link]
[Link]
Objectives
Ø Tablet: sm
Aside 3, 4 stacked
Ø Smartphone : sm
All stacked.
Besides 3,4 hidden
Tests
[Link]
[Link]
Ø Syntax
<div class="clearfix visible-sm-block"></div>
Ø Solution
On a 3 "row": header, aside, section, footer
The row header and footer span 12 columns.
The row with the left aside (1,2), the section and the right aside (3,4) is divided into 3 blocks with their
column names.
The number of columns depends on the size of the screen.
<header class="row"><div class="col-md-12">
<div class="row">
!-- displays of aside 1,2 - section - aside 3,4
lg, md : sm2 - md8 - md2
sm : sm2 - sm10 - 12(stack)
xs: 12(stacked) - 12(stacked) - hidden(hidden)
-->
col-sm-2 aside
col-sm-10 col-md-8
Ø Computer: lg and md
Aside 1,2 on 2 columns, Section on 8 columns, Aside 3,4 on 2 columns.
Ø Tablet: sm
Aside 3, 4 stacked
As there is a 'float' between aside 1, 2, and section, aside 3 and 4 are positioned incorrectly and overlap the blocks.
aside1,2 and section.
Ø sm
To hide Aside 3,4:
Ø Unfolding
Example
[Link]
[Link]
Code
<html lang="en">
<head>
Bootstrap
<meta charset="utf-8">
<link
href="[Link]
[Link]" rel="stylesheet">
<link href="00_style.css" rel="stylesheet">
</head>
<body>
Navbar component, in the body, not in the container
<nav class="nvabar navbar-defautl">
The nav-header describes the menu bar
<div class="nav-header">
The navbar-toggle collapsed handles the menu that collapses into
smartphone
<button class="navbar-toggle collapsed" data-
toggle="collapse" data-target="#monmenu">
MENU
</nav>
<div class="container-fluid">
</div><!--container-->
<script
src="[Link]
<script
src="[Link]
.[Link]"></script>
</body>
</html>
Dropdown version
Ø Unfolding
Code
right
Resolution problem
Principle
With small photos, you have to be careful that, when stacking them, they do not become
big... and blurry!
Vague example!
[Link]
[Link]
<div class="col-lg-2">
<img src="images/[Link]" alt="Mommy">
Solution
Ø The solution: control the number of photos displayed for each screen
[Link]
List
[Link]
Table
[Link]
Form
The provided text is a URL and does not contain translatable content.
Form generator site (see HTML view):
[Link]
Image
[Link]
Button
The provided text is a URL and does not contain translatable text.
Button generator site:
[Link]
other site :
The provided text is a URL and contains no translatable content.
Icons
[Link]
Glyphicons site:
Invalid input for translation.
another icon site
[Link]
etc. !
Collapse
[Link]
Navigation bar
[Link]
Pagination
The provided text is a URL and does not contain any translatable content.
Example of pagination with Jquery and Javascript:
Ø Example: 11_pagination-[Link]
Ø Example: 12_the_lists.html
Media
To place a photo or a video aligned to the right or left with text.
[Link]
Navigation
Navigation path: breadcrumb
[Link]
Carrousel
[Link]
etc. !