Responsive Design CSS. Offers CSS hooks to adjust behavior of page as you change the size, along with other goodies.
Uses a 12-column grid format, in other words you can divide any section into 12 pieces (or any divisor of 12). We'll see details later.
Any of these settings can be adjusted by editing LESS files.
- Standard font settings for sans-serif fonts, 14 pixels base size.
- Can add smaller dimmer text by using
<small>tags. - Can use
class='lead'to indicate a leading paragraph. Larger font size, lighter weight, taller. <small>shrinks text by 85% on normal body.- Can use
<strong>and<em>for bold and italic. - Other classes that change appearance:
muted,text-warning,text-error,text-info,text-success. By default, these mostly carry color changes. <abbr>tags will get presentation settings, and different ones if they carry.initialismclass.<address>tags are viadisplay: block, need to use<br>to create multiple lines.- Use
<blockquote>for quotes. Wrap subsections in<p>, sign them by<small>. Use<cite>if needed. Add a class of.pull-rightto have it float right. - Bootstrap also offers formatting for the 3 list types:
<ul>,<ol>,<dl>. Class of.unstyledwould remove the bullets. Use.dl-horizontalclass to make definition lists horizontal (<dd>and<dt>on same line). - Code should use
<code>for inline,<pre>for block.
- Table elements supported:
<table>,<thead>,<tbody>,<tr>,<td>,<th>,<caption>. Addclass='table'to the<table>element. - Other optional table classes:
.table-striped,.table-bordered,.table-hover, and.table-condensed. - Classes for table rows:
.success,.error,.warning,.info.
- Form formatting comes by default, no classes needed.
- Use
.form-searchon the<form>tag, and.search-queryon the<input>tag for nicer search boxes/buttons. - Use
.form-inlineclass to make the whole form on one line. - To create a form where labels and corresponding inputs are on the same line: Class
.form-horizontalon the<form>, wrap label and input in a.control-groupdiv, add.control-labelclass to labels, wrap associated controls to a.controlsdiv for alignment. - Wrap inputs inside the labels for them.
inputsupported types:text,password,datetime,datetime-local,date,month,time,week,number,email,URL,search,tel, andcolor.checkboxandradioinputs: Set those words as class attributes to the corresponding labels.- For multiple
checkboxes on same line, add.inlineclass to labels. - To add content right before or after an input, wrap the input in a div with
.input-prependor.input-appendclass, and put the item you want to place in a<span>with class.add-on. Can also use<button>with classbtninstead of span. Works real nice in a search form. - Input box sizes classes:
input-mini,input-small,input-medium,input-large,input-xlarge,input-xxlarge .uneditable-input- Put form actions in a
.horizontal-form. - For form help text
<span>s, use.help-inlineor.help-block. - Form control states:
:hover,disabled,.warning,.error,.success.
- Button/Link classes:
btn,btn btn-primary,btn btn-info,btn-success,btn btn-warning,btn btn-danger,btn btn-inverse,btn btn-link. - Button sizes:
.btn-large,.btn-small, or.btn-mini. - "Block level buttons":
.btn-block. Disabled:.disabled. - Image classes:
img-rounded,img-circle,img-polaroid. - 140 icons we can use. Get them as an
<i>tag with classicon-whatever. Eg:<i class="icon-edit"></i>. Add.icon-whitefor white icons. - Can make "button groups" with
.btn-toolbarand.btn-group, and putting the icons inside<a class="btn">tags
Javascript plugins offering standard widgets.
- Use
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">. - List items for the choices, with
<a>tags in them. - Can set a
.dividerclass on a list item for a divider. - Use
.pull-rightclass to right-align the menu on its parent object. - Use
.dropdown-submenuon a list item to turn it into a submenu.
- Form button groups with a
.btn-groupclassed div. - Populate it with
.btnclassed<button>s. - The corner buttons of the group get rounded corners on their outside.
- Wrap multiple groups in a
.btn-toolbardiv to place them all in one line. - For vertical stacking, use
.btn-group-verticalalong with.btn-group. - For a button with a dropdown, wrap the button and dropdown menu in a
.btn-group. You can also use<span class="caret"></span>to indicate it is a dropdown. Need somedata-togglesettings to make it work, more on that later. - Dropup menus, use
.dropupalongside.btn-group.
- Use
.navclass. - Use
.activeto indicate the current element. - Some styles:
.nav-tabs,.nav-pills. - Use
.disabledfor a disabled link. .nav-stackedfor vertical stacking.- Can combine with dropdowns.
- For "navigation lists" use
.nav-list, and.nav-headerfor the list headers. - For "tabbable navigation", use a
.tab-contentdiv, with.tab-panedivs in it, optionally with.fadeon them.data-toggles to make the connections. Enclose nav-bar and tab content in atabbablediv. Optionally with.tabs-belowor.tabs-leftetc.
Main navigation bar up top, including branding.
navbardiv for the external container.navbar-innerdiv inside it.- Use
brand<a>tag for brand logo/title. navfor the actual link list.- Use
.divider-verticalfor a vertical divider. - Forms in the navbar use
.navbar-form. Use.pull-leftor.pull-rightto place them. - For search forms, use
.navbar-searchinstead. - For a fixed navbar on the top of the page, use
.navbar-fixed-topand add 40px of padding on the<body>. Conversely with.navbar-fixed-bottom. - Other option:
.navbar-static-top. - For a responsive navbar: Use
.nav-collapse.collapseon the content that is to collapse, and.btn-navbaron the toggling button, with some data-toggle features on it. Use three<span>s with.icon-barfor a classical button look. Will needbootstrap-responsive.cssandcollapse.jsor the fullbootstrap.js. .navbar-inversefor an inverted color look.
- Use a
<ul>with class.breadcrumb. - Class
.divideron the<span>separators, use any symbol you want for them:/,→,»etc.
- Simply put a
.paginationdiv, and a<ul>list in it. - Can center it with
.pagination-centered. - Can use
.disabledor.activeon some<li>s. - Control the size with
.pagination-large,.pagination-small,.pagination-mini. - Can also instead drop the div, and use
.pagerclass on the<ul>. You can use.previousor.nextclasses on the<li>s to align them.
- Make them with
<span>elements with.labelclass. - Append
.label-success,.label-warning,.label-important,.label-info,.label-inverse. - Can make "badges" instead, with more rounded corners, using
.badgeetc instead.
- "Hero units" via the
.hero-unitclass. Used for big landing page content. - Use
.page-headeron the heading div for some extra spacing and font sizes. .thumbnailclass for a thumbnail. Use it on the containing<a>. Place them in a.thumbnails<ul>. Can use.captiontoo.- Alerts via
.alertclass on the div. Usedata-dismiss="alert"on the button to close the alert. Use.alert-blockfor multiline alerts. Other color options via.alert-error,.alert-success, or.alert-info. - Progress bars:
.progress,.progress-striped..activeto make it "live"..bar.bar-successor.bar-erroretc in containing divs. Might need to also set: `style="width: 35%;" or whatnot. - "Media objects" via a
.mediadiv, and.media-object,.media-body,.media-headingetc in it. Can use.pull-leftand friends. Enclose multiple objects in a.media-listdiv.
- Use
.wellin a container div to make the content look sunk. Also.well-largeand.well-small. .pull-left,.pull-rightto float things..clearfixto clear floats.
13 jQuery plugins that enhance Bootstrap.
Used via a data- API. No need to write much Javascript.
Some examples:
- Sliding or fading in modals
- Fading out tabs
- Fading out alerts
- Sliding carousel panes
For modal windows.
- Use
modal hide fadeclasses on the div. - Can use
.modal-header,.modal-body,.modal-footerfor parts. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>- Call the modal from a link:
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a> - Call from Javascript:
$('#myModal').modal(options). - Options to be passed via either
data-attributes or from Javascript:backdropif it closes by clicking outside of it.keyboardto be able to close it viaEsc.showstarts with it shown.remoteprovide path to inject content using jQuery'sload.
$('#myModal').modal('toggle').$('#myModal').modal('show').$('#myModal').modal('hide').- Events to listen to:
show(method fired),shown(actually shown to user),hide,hidden.
Example:
<li class="dropdown">
<a href="#" id="drop" role="button" class="dropdown-toggle" data-toggle="dropdown">Word <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="drop">
<li><a tabindex="-1" href="#">MAKE magazine</a></li>
<li><a tabindex="-1" href="#">WordPress DevelopmentS</a></li>
<li><a tabindex="-1" href="#">Speaking Engagements</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">Social Media</a></li>
</ul>
</li>
To use in javascript: $('.dropdown-toggle').dropdown(), $().dropdown('toggle').
Allows targetting sections of the page based on scroll position.
- To use, add
data-spy="scroll"anddata-target=".navbar"to the<body>tag. Then in the navbar have page anchors like<a href="#pork">Pork</a></li>. The plugin will set the.activestate to the appropriate anchor. - Can also do:
$('#navbar').scrollspy(). - Options:
offset, by about 50 pixels if using a fixed navbar.activateis an event that fires when.activechanges.
Example:
<ul class="nav nav-tabs">
<li><a href="#home" data-toggle="tab">Home</a></li>
<li><a href="#profile" data-toggle="tab">Profile</a></li>
<li><a href="#messages" data-toggle="tab">Messages</a></li>
<li><a href="#settings" data-toggle="tab">Settings</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">...</div>
<div class="tab-pane" id="profile">...</div>
<div class="tab-pane" id="messages">...</div>
<div class="tab-pane" id="settings">...</div>
</div>
To programmatically enable tabs:
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
})
Ways to toggle tabs:
('#myTab a[href="#profile"]').tab('show'); // Select tab by name
$('#myTab a:first').tab('show'); // Select first tab
$('#myTab a:last').tab('show'); // Select last tab
$('#myTab li:eq(2) a').tab('show'); // Select third tab (0-indexed)
Events to listen to: show, shown.
<a href="#" rel="tooltip" title="This is the tooltip">Tooltip Example</a>
$('#example').tooltip(options)
Options (either through javascript or via data-):
animation: Adds a fade transitionhtml: The "title" is interpreted as htmlplacement: "top", "bottom", "left", "right"selector: Tooltip objects will be delegated to the specified objects, if not falsetitle: Default tooltip value if nottitleattribute presenttrigger: "hover", "click", "focus", "manually"delay: Either a single number, or{ show: 500, hide: 300 }
Methods:
$().tooltip(options)
$('#element').tooltip('show')
$('#element').tooltip('hide')
$('#element').tooltip('toggle')
$('#element').tooltip('destroy')
Extended view version of tooltips.
Example:
<a href="#" class="btn" rel="popover" title="Using Popover" data-content="Just add content to the data-content attribute.">Click Me!</a>
Javascript call: $('#example').popover(options)
Options:
animation: Adds a fade transitionhtml: The "title" is interpreted as htmlplacement: "top", "bottom", "left", "right"selector: Tooltip objects will be delegated to the specified objects, if not falsetitle: Default tooltip value if nottitleattribute presentcontent: Default contentdelay: Either a single number, or{ show: 500, hide: 300 }
Methods:
$().popover(options)
$('#element').popover('show')
$('#element').popover('hide')
$('#element').popover('toggle')
$('#element').popover('destroy')
Implemented via a .alert class.
Can add dismiss functionality to them via: <a class="close" data-dismiss="alert" href="#">×</a> or $(".alert").alert().
Events: close, closed.
- Can use something like:
data-loading-text="Loading..."to give it a "loading state" status. - A button with
data-toggle="button"becomes "toggleable": clicking on it toggles the.activeclass. - Can make a button group act as "checkboxes" by setting
data-toggle="buttons-checkbox"in the.btn-groupdiv. - Similarly for radio buttons, use
data-toggle="buttons-radio".
Methods:
$().button('toggle')
$().button('reset')
$().button('someString')
This plugin makes it easy to add collapsible divisions of the page. Can be used for accordions.
Use class="accordion-toggle" data-toggle="collapse".
Better to look at some existing examples.
Standard methods and events.
Example code:
<div id="myCarousel" class="carousel slide">
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">...</div>
<div class="item">...</div>
<div class="item">...</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
Options:
intervalin ms.pauseis set to 'hover' will pause while hovering over it.
Methods:
.carousel('cycle')
.carousel('pause')
.carousel('number')
.carousel('prev')
.carousel('next')
Events: slide, slid
For autocompletion in forms.
Add these attributes to the input: data-provide="typeahead", data-items="4", data-source="[ ... ]".
Options:
sourcearray or function that takes as input "query" string and "process" callback. Can call either synchronously or asynchronously.itemsnumber of items to displayminLengthof characters before it's triggeredmatcherfunction that determines if an item matches the current querysortermethod used to sort the resultsupdatermethod used to return the selected itemhighlighter
Can be used to lock divs in place.
Use as: <div data-spy="affix" data-offset-top="200">
Can also use affix-top or affix-bottom