Professional Documents
Culture Documents
Idiots Guide To Bootstrap
Idiots Guide To Bootstrap
Intro
Get your Bootstrap Project Started
The Project Files
Downloading the Bootstrap Files
Bootstrap Files: What and what for?
Leveraging Bootstrap
Applying Custom Styles
Customizing the Navbar
Styling the Banner
Mobile First
Mobile First: How it works
Advanced Grid System: Multi-column layout
Responsive Utilities
Bonuses
Tooltip.js
More Carousel.js options
Font Awesome
Adding a background image to the banner
Thousands of sites are built every day with The Twitter Bootstrap Framework. This is the most popular HTML, CSS and JavaScript
responsive framework. Every developer and designer should know or learn how to use it.
If you have never used Bootstrap before, you are probably missing out. Why?
Bootstrap saves you a lot of time The framework includes predefined CSS classes, styled HTML components and configured
Javascript plugins ready to use, to help developers design pages better and faster.
Well documented with a massive support system The framework is continuously maintained with regular updates and bug fixes.
Plus, the documentation is very easy and approachable for newbies.
Responsive and mobile first Bootstrap comes with great features allowing your design to work across devices, from very small to
large.
Free and open-source This is the biggest advantage of all. Bootstrap offers a free collection of features and tools. It is super simple
for developers to create responsive layouts in no time.
This step-by-step tutorial teaches you the fundamentals and tools you need to know to create responsive pages with much less effort.
Youll learn the power and flexibility of the framework with through step-by-step explanations and examples. We will cover the full
range of topics, from the simplest to the more advanced.
What you should know to make the most of this tutorial:
Do you know HTML and CSS?
If the answer is yes, you are in the right place.
You should know how to identify HTML tags to create a webpage, and use CSS (Cascading Stylesheet) to make it pretty.
Do you know Javascript?
A beginner level is enough. The Bootstrap documentation is very helpful, with plugins configuration kept simple.
Do you know Bootstrap?
No knowledge of Bootstrap is required. This tutorial is a complete beginners guide to get you started with the responsive framework.
What you will learn:
How to download the Bootstrap files
The pre-defined CSS classes and HTML styled components
The fluid grid system
The JavaScript plugins
Mobile first and the responsive utilities
Leveraging and customizing the Bootstrap resources
And, a few bonuses!
So, lets begin!
(source: http://getbootstrap.com/getting-started/_
Once you have downloaded, unzipped and saved everything in a convenient place, we can have a look at whats inside:
You will see other files with the .map extension like this:
bootstrap.css.map
bootstrap-theme.css.map
You are now all set and ready to start your learning experience with Bootstrap!
We will kick off with the page layout.
Together, we want to build a one-page portfolio with:
An eye-catching banner
A portfolio gallery to showcase work projects, services and customer testimonials.
This should be a great way to get introduced to the Bootstrap library.
Well, Bootstrap has already done the hard work for you. We will not be building everything from the ground. We will show you how.
In your code editor, open index.html. You will only need this file open for a moment.
In your index.html file, you will see that we have already made some code available. We will change a few things.
This will keep the navbar glued to the top. When you scroll down the page, the navbar stays in place.
Conversely, you can also use .navbar-fixed-bottom to have the navbar fixed to the bottom.
Component alignment
Now, the navbar would look better with the brand name on one side and the menu on the other side. The component alignment will
do the job perfectly.
By default, an HTML element is aligned to the left. Adding the class .navbar-right allows you to float the element to the right.
alt=>
The image source is images/bootstrap-logo.png
And there you have it: a nice navbar fixed to the top with the Bootstrap logo and the menu on the right.
A banner to impress
The banner is a key element to make your content
compelling and powerful. The jumbotron seems like the perfect choice for it.
Jumbotron
The jumbotron is a grey box with rounded corners. It will serve to call extra attention to the banner we are about to build.
As shown below:
copy the code snippet
add to your source code inside <div id=banner>
To get this:
Final result:
The .container represents the highest level of the grid system structure.
Within the .container, we add the .row, which, as you may expect, creates a row.
You can then complete the grid layout by adding columns.
The above grid example above, with 3 div elements and the class.col-md-4, will render like this:
Services Section
In our template, inside the section <div id=services>
Add a div .container
Within the container, add the .row to include the columns.
The expected result is 3 paragraphs on 1 row.
We are only targeting the desktop and large screens for the moment.
So, we add 3 divs and.col-md-4 like so:
<div class="col-md-3">
<a href="#" class="thumbnail">
<img src="images/projects/web-template.png" alt="image">
</a>
</div>
We are almost done with the footer. Next, we are adding alabel and a glyphicon.
Labels
The page was designed with Bootstrap v.3.3.5 and we want to highlight it with a label. It works like the button with a common class
.label and modifier class to add the styling and a color.
Wrap Bootstrap v.3.3.5 within <span> tags
Add the common class .label to the opening <span> tag
Choose a modifier class to add color.
We will add .label-primary
Glyphicons
Glyphicons are free to use with the Bootstrap resources.
Every glyph has a common class .glyphicon, then another class specific to the glyphicon selected.
We are going to use glyphicon-heart to display Designed with
Inside the second <p>, add a <span>
Inside the <span>, use the class .glyphicon and .glyphicon-heart like so:
The role of glyphicons is purely decorative, so to hide them from assistive devices (screen readers) we add the attributeariahidden=true
Here you go:
Good job!
Next, were going to take another step further into the Bootstrap learning experience with the JavaScript plugins.
Carousel.js
Below the projects gallery, we have included a testimonials section so visitors can read through reviews left by satisfied customers.
Given the great amount of content possible, displaying 4 or 5 testimonials could use up a lot of real estate. Therefore, we will include a
carousel to allow visitors to slide through testimonials one after another instead of scrolling down the page. Real smooth!
So, lets build a slideshow of testimonials.
To build the slideshow, we will use:
Carousel.js
Media objects
Testimonials Slideshow
Copy the first markup example available on the documentation
Try it now!
You will see the structure of the carousel with 2 controls (left and right arrows) on each side. There is no content for now.
Next, we will add the content: the testimonials.
Media Object
Inside each .item slide, we add a media object.
Copy the code example available in the documentation and paste directly inside the.item.
Get rid of the <div> and <img> tags of the .item slide
And, replace them with the media object code snippet.
We now repeat the process from the top to have 3 (or more) slides in total.
Add an .item slide
Add a .container
Include a .row and 8 columns with .col-md-8
And, offset by 2 columns with.col-md-offset-2
Add the media object markup.
Finally, change the image shape with .img-circle
Thats it! Now visitors can enjoy cycling and reading through your clients testimonials. What a treat!
Pop-up Modal
The Modal plugin is like a dialog box or a pop up window used to display information to visitors.
We will add a modal to the jumbotron section. You remember with the call-to-action button, right?
Clicking the button will make a window pop up to display well, we wont tell you right now.
For now, we will show you how to create a modal via data-attributes.
2-step process
On the bootstrap documentation, lets head over to the javascript section and select modal.js to see how the markup looks:
We first need a trigger button.
data-target and data- toggle are data-attributes that you embed inside your markup to bind the HTML elements with javascript.
Example:
In the jumbotron:
Inside the button element is where we add data-target=#contactMe and data-toggle=modal. This is the trigger button.
Change the text to Contact Me!.
<p>
<a class="btn btn-warning btn-lg" href="#" data-toggle="modal" data-target="#contactMe" href="#" role="button">
</p>
Very important: the data-target and the identifier must match. So, remember to update thedata-target=#contactMe inside the
trigger button, to match the id=contactMe in the modal.
Try it now!
When you click on Contact Me, the button will fire off the modal dialog and display surprise! A contact form:
Inside the .modal-body, we have added a contact form. You can also include:
A video
An image
Or, remote content
We will make a detour to the CSS section to explain how to set up a contact form.
Contact Form Modal
This is a great example of a pre-styled and enhanced HTML element. Form elements are ready to use with no extra styling required.
Here is how we did it:
The form documentation includes code examples and snippets that make the process straightforward.
We have pasted the HTML form code snippet inside the.modal-body
And, we have kept just what we need:
fields for the name and an email address
and, a textarea for the message.
Each label and input is wrapped in a .form-group
The for and id attributes must always match to allow autofocus.
Forms add-ons and variations include:
Static Control
Focus, disabled and readonly State
Help text
And, control sizing
We will look at the 2 last ones: help text and control sizing.
A help text is extra information to the user.
Below the textarea, we add the following code:
(optional) Add the attribute aria-describedby=helpBlock inside the associated input or textarea for assistive technologies such as
screen readers.
Control sizing is made possible with super helpful classes like.input-lg and .input-sm
Try .input-lg inside each input to see how it renders.
<div class="form-group">
<label for="sender-name" class="control-label input-lg">Name:</label>
<input type="text" class="form-control input-lg" id="sender-name">
</div>
List-inline
Below the submit button, we have added an additional modal-footer to include a list of social media links.
<li> are, by default, block-level elements, meaning each will use one line.
In order to display the social media links on one single line, we use .list-inline like this:
<ul class="list-inline">
This will result in an inline list like below, when the modal dialog opens up:
Try it!
Scrollspy navigation
The scrollspy plugin watches for position change on a webpage to automatically update the active state of the navigation links.
It means literally what its called.
Spy = it spies on the element to which it is attached
Scroll = it updates based on the scroll position
We will add the scrollspy behavior to the navigation bar. Just like the modal.js, it requires 2 steps:
We add the data-attribute data-spy=scroll to the element we want to spy. We will add this one to the<body> element:
<body data-spy="scroll">
The data-target refers to the element we want to update with the active state. In this case, this is the menu navigationhome,
(
services
and projects). This one will have a unique identifier.
Inside the div that wraps the unordered list <ul>, add a unique identifier.
Try it now!
When you click a menu link, the page skips to the targeted section and the link automatically updates to active. This is a much better
user experience.
Bootstrap can help achieve great results with little to no effort. Look at the portfolio that you just built. Impressive!
Next, we will take your Bootstrap experience to the next level by teaching you how to combine default and custom styling.
Leveraging Bootstrap
Looking at the source code of some websites, it is very common to find properties from Bootstrap. However, you could not guess by
just looking at the interface. These sites look nothing like Bootstrap.
Many developers and designers use Bootstrap to get a quick start in their project. Their expertise allows them to fully take advantage
of the framework while staying in control of their design.
You can do it too!
We will show you how to do that in a manner that is quick, effective and non-obstructive.
Very important: you never ever want to change the bootstrap files: bootstrap.css or bootstrap.js.
This is recommended practice to keep your custom style and the Bootstrap files separate.
Your custom style must be in style.css or else.
And, the bootstrap files remain untouched.
Naturally, you must add your style.css stylesheet in the head section of theindex.html, like we did for you.
The goal here is to override the default Bootstrap CSS. To do so, your custom style always comes last. This follows the rule of
Cascading Stylesheets, so CSS rules positioned last take precedent.
And, this is how we can start customizing Bootstrap.
We also target .navbar-brand in case you should decide to keep a text link in lieu of the bootstrap logo.
Finally, we align the text links with .text-center in the HTML markup
In the console, the left side allows to inspect the DOM (Document Object Model)
The right side provides you with styling details about the HTML element inspected (highlighted)
Try it yourself! Highlight the jumbotron, click right and select inspect element to open the console.
As seen on the console, the .jumbotron class has the following CSS rules.
We want to override: .jumbotron {background-color: #eee}
Once your custom change is applied, you notice that the information on the console has changed.
Your custom style.css is available first, meaning that it takes precedence over other styles.
If you scroll down the console a little, you will see that the same selector originating from the bootstrap.min.css is stricken
through, meaning that it has been overridden by your custom style.
If you use Firefox,firebug will help you through the same process.
Web developer tools for other browsers are listed here.
Font size
As part of the customization, we make the headings bigger with.font70 and .font80.
These rules are available at the top of style.css.
Complete the code like below:
Same for the headings of the sections services, projects and testimonials:
<h1 class="font60">Services</h1>
<h1 class="font60">Projects</h1>
<h1 class="font60">Testimonials</h1>
.jumbotron {
Background: transparent;
color: #ecf0f1;
}
Mobile First
There are over 3.1 billion mobile web users worldwide. In the U.S. alone, 25% of mobile web users use mobile only. And, the numbers
keep growing.
Mobile first is an important concept to consider. As the web landscape becomes increasingly complex, it is becoming even more
challenging for developers and designers to create the best universal web experience.
Thankfully, the Bootstrap framework is responsive, flexible and mobile first. It provides great tools and solutions to help build layouts
that can gracefully adapt to any device.
Lets see it in action with a quick demo.
Try to reduce the size of your browser and watch what happens.
First, the navigation bar is replaced with a square-shaped icon with 3 lines across it.
Clicking the icon will toggle the menu up and down to alternately reveal and hide the menu content.
On a large screen, we see a horizontal menu that turns into a collapsed menu when switching to a small screen. Genius!
This is a great example of adaptive design that Bootstrap can help us achieve with little effort.
However, not everything looks as nice on a small device as on a desktop view.
When you scroll down the page, you may notice a few areas that need improvement.
The pre-defined grid options classes and the responsive utilities will come to the rescue.
In this part, we are about to take it up a notch with more control over how your design renders on multiple devices.
Topics include:
Mobile first: How it works
The advanced grid system with multiple-column layouts
The responsive utilities
The viewport meta tag
And, the media queries
Full-width looks best on a smaller screen hence the concept of mobile first. So, we wont change anything here.
However, if you decide to override mobile first on a tablet, you would use the class.col-sm-4 to target 768px-wide devices and larger.
Lets try that next.
</div>
On tablet view, the class .col-sm-6 will limit the number of images to 2 per row, while the number will remain at 4 on a desktop view
with .col-md-3.
See below if it makes more sense:
Desktop view
Now, going even smaller, like on a smartphone, things start to get a bit cluttered. There is a lot going on. And, we have a lot to scroll
down through before reaching the bottom.
To improve the mobile user experience, it is best to keep the content to a minimum and limit the number of images to 4 in total.
How so? By making one row invisible. This is when the responsive utilities come into play.
Responsive utilities
Just like the grid options, responsive utilities allow more flexibility in the responsive layout. Their purpose is to make elements visible
or invisible based on breakpoints.
In Responsive Web Design, breakpoints are used to target different devices with specific styling.
Hidden row
To make the second row disappear when we reach the small (<768px) breakpoint, we use .hidden-xs.
</section><!testimonial -->
Inside the .container, we add:
A <h1>
And, a media object (the same that we have inside the carousel) like so:
Now, the goal is to make the content interchangeable and adaptive based on the viewport size.
.visible-xs makes the content visible on small devices only
Conversely, .hidden-xs hides the content on small devices
To do so:
We add .hidden-xs to the container with the carousel
The idea is to duplicate headings in the markup and to alternately display them as the screen size decreases.
In the banner, update the code like this:
Now, you are probably wondering how the browser can figure out which class to apply. This is when the meta viewport tag comes into
play.
The viewport represents the visible area of a page, which varies as the device size gets smaller or larger.
With the viewport meta tag, the width of the screen is detected and the information is sent to the browser, which knows the CSS to
apply for a specific breakpoint. It lets you control how you want your site to display on different screen sizes.
For better control over cross-platform responsive design, you can write styling that will take effect for specific breakpoints. CSS lets
you define it with the media queries.
Media Queries
The @media rule is used to define different styling for key breakpoints.
Some global styling was not really to our liking.
So, in style.css, we use the @media rule to write custom styling for the navigation links and the footer to better fit the small screen
view.
Footer
For the footer, the columns become full-width automatically with mobile first.
However, we use text alignment classes in the markup and it looks funny on a small screen.
So, we adjust like so:
text-align:left
Plus, we are adding a little bit of margin on the top and bottom.
In the media queries, update with the code below:
footer p {
text-align: left;
margin: 3px 0;
}
Bootstrap provides a table of media queries that you can use in FEWER files. Replace the @variables with numerical values to define
your breakpoints and you are good to go.
Congrats for making it this far! Still cant get enough of Bootstrap?
There is more to come, and we have saved the best for last. Here come the bonuses!
BONUSES
Topics include:
Tootip.js
Carousel.js
Font Awesome
Adding a background image to the banner
Tooltip.js
Tooltip.js is a quick way to display extended information on mouseover, like the example below when hovering over an image.
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
Thats more time to read all the great feedback left by customers!
You also can allow a pause between each slide.
A CDN is a Content Delivery Network, or a system of distributed servers that delivers content based on the users geographical
location.
This is like using a regular stylesheet, except that the file is hosted on an external server. Therefore, the page is lighter and loads much
faster.
Now, we are going to seeexamples of icons and see how to add them to our designs.
To add a Font Awesome icon, use <i> tags
The common class is .fa
Then, add a modifier for the icon selected. Example: .fa-camera-retro
Here is the result:
Font Awesome is in font format, so we can customize with the CSS color property in style.css:
#services i {
color: #3498db;
}
We do the same for the contact form in the modal dialog. In the modal footer, we have included text links that we will replace with
font icons.
From this:
To this:
In the modal element, we replace the text links with social media font icons.
The markup looks like this:
<ul class="list-inline">
<li><a href="#"><i class="fa fa-facebook-square fa-3x"></i></a></li>
<li><a href="#"><i class="fa fa-twitter fa-3x"></i></a></li>
<li><a href="#"><i class="fa fa-linkedin fa-3x"></i></a></li>
<li><a href="#"><i class="fa fa-github fa-3x"></i></a></li>
</ul>
Background Image
This is the final touch to wrap it all up.
In the project files, we have added background imagesimages/background.
In style.css, we can update like so:
#banner {
background: url("../images/background/bg-1.jpg");
background-size: cover;
}
Try it!
We hope you enjoyed this tutorial.
You are now well on your way to creating some awesome pages.
To further your learning with Bootstrap, watch Start Now With Bootstrap and create a portfolio website with HTML, CSS & Bootstrap.
These 5 hours of video content will get you up to speed with the front-end framework. Practice makes perfect.
Photo courtesy of Unsplash and Freepik
POPULAR POSTS
How to Build an iPhone App from Scratch for Non-Technical People: Your quick and dirty guide
Excel Formulas: 10 Formulas That Helped Me Keep My Job
Code Wars: Ruby vs Python vs PHP [Infographic]
Top 10 Programming Languages to Learn in 2014
How to Add Ringtones To Your iPhone (Updated for iOS 7)
8 Best PowerPoint Presentations: How To Create Engaging Presentations
Java Interview Questions: How to crack the TOP 15 questions
Drupal vs Joomla vs WordPress: CMS Showdown [infographic]
Making an App: 6 Things You Should Consider Before Getting Started
10 Frmulas de Excel para ser Ms Productivo