🔙 Quay lại trang tải sách pdf ebook Bootstrap, Responsive Web Development Ebooks Nhóm Zalo Bootstrap Dave Winer and Jake Spurlock Bootstrap by Dave Winer and Jake Spurlock Copyright © 2010 Jake Spurlock. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editors: Simon St. Laurent and Meghan Blanchette Production Editor: Marisa LaFleur Copyeditor: Proofreader: FIX ME! May 2013: First Edition Revision History for the First Edition: YYYY-MM-DD: First release Indexer: Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano See http://oreilly.com/catalog/errata.csp?isbn=9781449343910 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. !!FILL THIS IN!! and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐ mark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-449-34391-0 [?] Table of Contents Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. Bootstrap Scaffolding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What is Bootstrap 1 Bootstrap File Structure 2 Basic HTML Template 2 Global Styles 3 Default Grid System 3 Basic grid HTML 4 Offsetting Columns 4 Nesting columns 5 Excercise 1 5 Fluid Grid System 6 Container Layouts 7 Responsive Design 7 What is Responsive Design? 8 2. Bootstrap CSS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Typography 11 Headings 11 Emphasis classes 13 Lists 17 Code 20 Tables 20 Optional Table Classes 21 Table Row Classes 23 Forms 23 Optional Form Layouts 24 iii Supported Form Controls 26 Extending Form Controls 29 Form Control Sizing 31 Form Control States 35 Buttons 36 Button Sizes 38 Disabled Button Styling 39 Images 40 Icons 40 Glyphicon Attribution 41 Usage 42 3. Bootstrap Layout Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Dropdown Menus 45 Options 46 Button Groups 46 Button Groups as Radio and Checkboxes 48 Buttons With Dropdowns 48 Split Button Dropdowns 49 Dropup Menus 50 Navigation Elements 51 Tabular Navigation 51 Basic Pills Navigation 51 Stackable Navs 52 Dropdowns 53 Navigation Lists 54 Tabbable Navigation 55 Navbar 58 Nav Links 59 Forms 60 Navbar Menu Variations 60 Breadcrumbs 63 Pagination 64 Pager 66 Labels and Badges 67 Badges 67 Typographic Elements 68 Page Header 68 Thumbnails 69 Alerts 70 Progress bars 72 Media Object 73 iv | Table of Contents Misc 76 Helper Classes 77 4. Bootstrap Javascript Plugins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Overview 79 Programattic API 80 Transitions 80 Modal 81 Using Modal through Data Attributes 82 Modal Options 82 Methods 83 Events 83 Dropdown 84 Dropdown Usage via the Data API 84 Dropdown Usage via Javascript 85 Methods 85 Scrollspy 85 Usage 85 Scrollspy Methods 86 Options 86 Events 86 Toggleable Tabs 86 Usage 87 Events 88 Tooltips 88 Usage 88 Options 89 Methods 89 Show 89 Popover 90 Usage 90 Options 90 Methods 91 Alerts 91 Usage 92 Methods 92 Events 92 Buttons 92 Loading State 93 Single Toggle 93 Checkbox Buttons 93 Radio Buttons 94 Table of Contents | v Usage 94 Methods 94 Collapse 95 Usage 96 Options 96 Methods 97 Events 97 Carousel 97 Usage 98 Options 98 Methods 99 Events 99 Typeahead 100 Usage 100 Options 101 Affix 101 Usage 101 Options 102 5. Using Bootstrap. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Github Project 103 Customizing Bootstrap 103 Using LESS 104 Text Snippets 106 Photoshop Templates 107 Themes 108 Built with Bootstrap 108 Conclusion 108 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 vi | Table of Contents Foreword I was a software developer before there was a Mac, so I remember something not a lot of programmers do. I remember how the tech industry reacted to it. And for the most part, it was with a fair amount of skepticism. And the interesting thing is that the negative things people say about Bootstrap today sound exactly like the negative things people said about the Mac in 1984. And in both cases, the things that people didn’t like were what made them important. What the Mac realized is that there are a set of things that all software has to do, so why shouldn’t they all do them the same way? If they did, software would be easier to develop and debug, but more important — it would be easier to use. If there was only one way to do menus, then once a user learned how to use the menus of one app, they’d already know how to use the menus of all others. Same with scrollbars, windows, the keyboard, the mouse, printing, sound. The reason programmers didn’t like it, and I was one of them, was that they took what we did and commoditized it. Further, there were limits to the one-size-fits-all approach. There were some apps that didn’t take to the UI standards very well. What to do about them? Well, you adapted, that’s what you did. This is a well-known technical process called factoring. If you see yourself doing some‐ thing over and over, do it one more time, really well, and work on the API so it’s really easy and flexible, and that’s it. You never do it again. It’s how you build ever-taller build‐ ings out of software. And what was the leading-edge five years ago, is baked into the operating system today. Progress. It’s a wonderful thing! :-) The same patterns are observable in the web. In fact, it’s kind of sad how much of a repeat it is, how backward today’s development environment is compared to the one envisioned by the Mac. But at least Bootstrap is out there doing the factoring. If I want to put up a menu, I can just use their code that does menus. Sure, my menu looks like all the others, but that’s a good thing, for users. No need to learn a second or third way to use a menu. vii That this is needed, desperately needed, is indicated by the incredible uptake of Boot‐ strap. I use it in all the server software I’m working on. And it shows through in the templating language I’m developing, so everyone who uses it will find it’s “just there” and works, any time you want to do a Bootstrap technique. Nothing to do, no libraries to include. It’s as if it were part of the hardware. Same approach that Apple took with the Mac OS in 1984. Like all important technologies, Bootstrap is “good enough” but not too good. In other words, the designers, Mark Otto and Jacob Thornton, could have factored more than they did, and created something more compact and perhaps more elegant, that wasn’t nearly as approachable. The great thing about Bootstrap for a guy like me, who has been busy building software behind websites, is that it solves a whole bunch of problems that we all have when putting a user interface on those sites. However I think that will turn out to be just the beginning. I see the opportunity for Bootstrap to become an integral part of the web. A toolkit that you can count on being present in every environment you work in. Further, someday, perhaps soon, designers will be able to plug in “skins” for Bootstrap, that transform the appearance of a site without any modification to the code or to its styles or scripts. I don’t see any limits to what can be done with Bootstrap. Rather than being a replacement for designers, it creates opportunities for designers to have more power and reach. These days, part of the maturing process of any new technology is the release of its O’Reilly book. Now Bootstrap has one. The author, Jake Spurlock, a web developer, has built a bunch of sites with Bootstrap, has spoken at conferences about it, and he credits me for getting him started with a series of enthusiastic blog posts I wrote, as I was discovering its power and elegance. Now, I can happily turn you over to Jake’s able hands, to show you how the Bootstrap magic works, so you too can help move the web devel‐ opment world forward. —Dave Winer, editor, Scripting News, January 2013, New York, NY viii | Foreword Preface Bootstrap is a front-end framework for building responsive websites. Whether it is application frameworks, blogs, or other CMS applications, Bootstrap can be a good fit as it can be as vanilla as you like. It’s combination of HTML, CSS, and Javascript make it easy to build robust sites, without adding a lot of code. With a default grid system, layouts come together with ease, and the styling of buttons, navs, and tables make basic markup look great from the get go. A dozen or so Javascript plugins catapult you into adding interactive elements to your site. Who This Book is For This books is mostly for people that have a good handle on HTML/CSS and Javascript, and are curious to get started with building responsive sites, adding the Bootstrap Java‐ script plugins, or building sites faster by using this popular open-source framework. Who This Book is Not For This book is not for people that get all they need out of the Bootstrap online documen‐ tation. Like a lot of people, the online docs are where I got started, building my first site with Bootstrap 1.3, and then upgrading it to Bootstrap 1.4. After that, a big project was built with Bootstrap 2.0 and on. If you are comfortable writing semantic HTML, then jumping into Bootstrap should be easy for you to get started with. What This Book Will Do For You With some background in writing HTML/CSS, and Javascript, this book will help you get off the ground writing some flexible code for responsive websites. In practical terms, the concepts and code syntax should come easily as it follows the patterns for writing semantic HTML and CSS anyways. ix How This Book Works This book tries to built a site with Bootstrap, starting at the foundation of the project, the file structure, moving up through the grid system, and layout types into HTML elements and styling like forms, tables, and buttons. Once the walls are up, we move into the aesthetic elements like navbars, breadcrumbs, and media objects. After that, into the Javascript elements that provide the interaction for a site like dropdowns, the carousel, and modals. Why I Wrote This Book I’m not an Bootstrap expert hoping to create more Bootstrap experts to get a lot of work done. I’m a developer and writer who encountered Bootstrap through a post on Dave Winer’s blog, and I thought that it would be cool to apply it to a new site that I was working on and since felt compelled to share some of that. I’m hoping that the path I followed will work for other people, probably with variations, and that a book written from a begin‐ ner’s perspective (and vetted by experts) would help more people find and enjoy Boot‐ strap. Other Resources This book may not be the best way for you to learn Bootstrap. It all depends on what you want to learn and why. If your primary interest is to get started building Bootstrap websites, the online docu‐ mentation at http://twitter.github.com/bootstrap/ may likely suit you perfectly. The authors, Jacob Thornton and Mark Otto have been meticulous in providing examples of the codebase, and HTML code samples, and more to kick start your project. It is top notch, and where I have gathered the structure for this book. If you want to contribute to the work of the open source project, you can submit pull requests, or use the issue tracker on the Github project, http://github.com/twitter/boot strap/, for updates, downloads, documentation, and more. Are You Sure You Want Bootstrap? If you are simply looking for Javscript plugins, or a CSS reset, Bootstrap maybe overkill. If you aren’t in love with some of the default interface elements that can be overwritten easily, or just strip out the associated tags. If you are looking for an easy way to build fast, responsive websites, Bootstrap is a great way to get going. I use it on all of my projects, and I’m really happy with it. x | Preface Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. This icon signifies a tip, suggestion, or general note. This icon indicates a warning or caution. Using Code Examples The examples in this book are meant to teach basic concepts in small bites. While you may certainly borrow code and reuse it as you see fit, you won’t be able to take the code of this book and build a stupendous application instantly (unless perhaps you have an unusual fondness for bacon and cats). You should, however, be able to figure out the steps you need to take to build a great website. You can download the code from the Examples link on the book’s page at hhttp:// shop.oreilly.com/product/0636920027867.do. This book is here to help you get your job done. In general, if this book includes code examples, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount Preface | xi of example code from this book into your product’s documentation does require per‐ mission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Bootstrap, Responsive Web Development, by Jake Spurlock (O’Reilly). Copyright 2013 Jake Spurlock, 9781449343910.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at [email protected]. Help This Book Grow While I hope that you will enjoy reading this book and learn from it, I also hope that you can contribute to helping other readers learn Bootstrap here. You can help your fellow readers in a number of ways: • If you find specific technical problems, bad explanations, or things that can be improved, please report them through the errata system at http://oreilly.com/cata log/errata.csp?isbn=0636920027867. • If you like (or don’t like) the book, please leave reviews. The most visible places to do so are on Amazon.com (or its international sites) and at the O’Reilly page for the book at http://shop.oreilly.com/product/0636920027867.do. Detailed explana‐ tions of what worked and what didn’t work for you (and the broader target audience of programmers new to Bootstrap) are helpful to other readers and to me. • If you find you have much more you want to say about Bootstrap, please consider sharing it, whether on the Web, in a book of your own, in training classes, or in whatever form you find easiest. I’ll update the book for errata, and try to address issues raised in reviews. Even once the book is complete, I may still add some extra pieces to it. If you purchased it as an ebook, you’ll receive these updates for free at least up to the point where it’s time for a whole new edition. I don’t expect that new edition declaration to come quickly, however, unless the Bootstrap world changes substantially. Hopefully this book will engage you enough to make you consider sharing. Safari® Books Online Safari Books Online is an on-demand digital library that delivers ex‐ pert content in both book and video form from the world’s leading authors in technology and business. xii | Preface Technology professionals, software developers, web designers, and business and crea‐ tive professionals use Safari Books Online as their primary resource for research, prob‐ lem solving, learning, and certification training. Safari Books Online offers a range of product mixes and pricing programs for organi‐ zations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Pro‐ fessional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technol‐ ogy, and dozens more. For more information about Safari Books Online, please visit us online. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://www.oreilly.com/catalog/. To comment or ask technical questions about this book, send email to bookques [email protected]. For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com. Find us on Facebook: http://facebook.com/oreilly Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Acknowledgments Many thanks to Dave Winer for interesting me in Bootstrap in the first place, and to Simon St. Laurent for the opportunity to write this. Detailed feedback from my friends Roseanne Fallin, and Tony Quartorolo has made it possible, I hope that this book can Preface | xiii get readers started on the right track. Thanks to Melissa Morgan for letting my take a few risks and develop the way that I like at MAKE too. In particular, thanks to my wonderful wife Melissa for putting up with me, and en‐ couraging me to finish. To my son Rush for understanding that I needed to “Work”, and to my daughter Hailey for the warm smiles and huge hugs. xiv | Preface CHAPTER 1 Bootstrap Scaffolding What is Bootstrap Bootstrap is an Open Source product from Mark Otto and Jacob Thornton who, when initially released were both employees at Twitter. There was a need to standardize the front end toolsets of engineers across the company. In the launch blog post, Mark Otto introduces the project like this: In the earlier days of Twitter, engineers used almost any library they were familiar with to meet front-end requirements. Inconsistencies among the individual applications made it difficult to scale and maintain them. Bootstrap began as an answer to these challenges and quickly accelerated during Twitter’s first Hackweek. By the end of Hackweek, we had reached a stable version that engineers could use across the company. — Mark Otto https://dev.twitter.com/blog/ bootstrap-twitter Since Bootstrap launched in August, 2011 it has taken off in popularity. It has evolved away from being an entirely CSS drivin project to include a host of Javascript plugins, and icons that go hand in hand with forms and buttons. At its base, it allows for re‐ sponsive web design, and features a robust 12 column, 940px wide grid. One of the highlights is the build tool on [Bootstrap’s](http://getbootstrap.com) website where you can customize the build to suit your needs, choosing what CSS and Javascript features that you want to include on your site. All of this, allows front-end web developement to be catapulted forward, building on a stable foundation of forward-looking design, and developement. Getting started with Bootstrap is as simple as dropping some CSS and Javascript into the root of your site. Starting a project new, Bootstrap comes comes with a handful of useful elements to get you started. Normally, when I start a project, I start with tools like Eric Meyer’s CSS reset, and get going on my web project. With Bootstrap, you just need to include the 1 bootstrap.css CSS file, and optionally the bootstrap.js Javascript file into your web‐ site and you are ready to go. Bootstrap File Structure bootstrap/ ├── css/ │ ├── bootstrap.css │ ├── bootstrap.min.css ├── js/ │ ├── bootstrap.js │ ├── bootstrap.min.js ├── img/ │ ├── glyphicons-halflings.png │ ├── glyphicons-halflings-white.png └── README.md The Bootstrap download includes three folders: css, js, and img. For simplicity, add these to the root of your project. Included are also minified versions of the CSS and Javascript. Both the uncompressed and the minified versions do not need to be included. For the sake of brevity, I use the uncompressed during development, and then switch to the compressed version in production. Basic HTML Template Normally, a web project looks something like this: Basic HTML Layout. Bootstrap 101 Template

Hello, world!

With Bootstrap, we simply include the link to the CSS stylesheet, and the Javascript. Basic Bootstrap Template. Bootstrap 101 Template

Hello, world!

2 | Chapter 1: Bootstrap Scaffolding NOTE Don’t forget the HTML 5 Doctype. By including , all modern browsers are put into standards mode. Global Styles With Bootstrap, a number of items come prebuilt. Instead of using the old reset block that was part of the Bootstrap 1.0 tree, Bootstrap 2.0 uses Normalize.css, a project from Nicolas Gallagher that is part of the HTML5 Boilerplate. This is included in the Boot‐ strap.css file. In particular, these default styles give special treatment to typography and links. • margin has been removed from the body, and content will snug up to the edges of the browser window. • background-color: white; is applied to the body • Bootstrap is using the @baseFontFamily, @baseFontSize, and @baseLine Height attributes as our typographic base. This allows the height of headings, and other content around the site to maintain a similar line height. • Bootstrap sets the global link color via @linkColor and applies link underlines only on :hover Remember, if you don’t like the colors, or want to change a default, this can be done in the you can change globals in any of the .less files. For this, update the scaffolding.less file, or overwrite colors in your own stylesheet that have on the site. Default Grid System The default Bootstrap grid system utilizes 12 columns, making for a 940px wide con‐ tainer without responsive features enabled. With the responsive CSS file added, the grid adapts to be 724px and 1170px wide depending on your viewport. Below 767px view‐ ports, for example, on tablets and smaller devices the columns become fluid and stack vertically. At the default width, each column is 60 pixels wide, offset 20 pixels to the left. Global Styles | 3 Figure 1-1. Default Grid Basic grid HTML To create a simple layout, create a container with a div that has a class of .row, and add the appropriate amount of .span* columns. Since we have 12-column grid, we just need to have the amount of .span* columns add up to twelve. We could use a 3-6-3 layout, 4-8, 3-5-4, 2-8-2, we could go on and on, but I think you get the gist. Basic Grid Layout.
...
...
In the above example, we have .span8, and a .span4 adding up to 12. http://jsfiddle.net/whyisjake/b3X7n/embedded/result/ Offsetting Columns You can move columns to the right using the .offset* class. Each class moves the span over that width. So an .offset2 would move a .span7 over two columns. Offsetting Columns.
...
...
4 | Chapter 1: Bootstrap Scaffolding Figure 1-2. Offset Grid Nesting columns To nest your content with the default grid, inside of a .span*, simply add a new .row with enough .span* that add up the number of spans of the parent container. So, let’s say that you have a two columns layout, with a span8, and a span4, and you want to embed a two column layout inside of the layout, what spans would you use? For a four column layout? Excercise 1 Create a table that looks like this: Table 1-1. ORM Employees First Last Sanders Kleinfeld Karen Tripp Adam Zaremba Write your solution here: First Last Sanders Kleinfeld Karen Tripp Adam Zaremba Solution Your markup should look something like this: .ORM Employees [options="header"] |======================= |First | Last |Sanders | Kleinfeld |Karen | Tripp Default Grid System | 5 |Adam | Zaremba |======================= Nesting Columns.
Level 1 column
Level 2
Level 2
Figure 1-3. Nesting Grid http://jsfiddle.net/whyisjake/EEWQ2/embedded/result/ Fluid Grid System The fluid grid system uses percents instead of pixels for column widths. It has the same responsive capabilities as our fixed grid system, ensuring proper proportions for key screen resolutions and devices. You can make any row “fluid” by changing .row to .row fluid. The column classes stay the exact same, making it easy to flip between fixed and fluid grids. To offset, you operate in the same way as the fixed grid system works by adding .offset* to any column to shift by your desired number of columns. http://jsfiddle.net/whyisjake/327R3/embedded/result/ Fluid Column Layout.
...
...
...
...
6 | Chapter 1: Bootstrap Scaffolding Nesting a fluid grid is a little different. Since we are using percentages, each .row resets the column count to 12. For example, If you were inside a .span8, instead of two .span4 elements to divide the content in half, you would use two .span6 divs. This is the case for responsive content, as we want the content to fill 100% of the container. Nesting Fluid Column Layout.
...
...
Figure 1-4. Nesting Fluid Grid Container Layouts To add a fixed width, centered layout to your page, simply wrap the content in
. If you would like to use a fluid layout, but want to wrap everything in a container, use the following:
. Us‐ ing a fluid layout is great when you are building applications, administration screens and other related projects. Responsive Design To turn on the responsive features of Bootstrap, you need to add a meta tag to the of your webpage. If you haven’t downloaded the compiled source, you will also need to add the responsive CSS file. An example of required files looks like this: Responsive Meta Tag and CSS. My amazing Bootstrap site! Container Layouts | 7 Heads up!If you get started and are finding that the Bootstrap respon‐ sive features aren’t working, make sure that you have these tags. The responsive features aren’t added by default at this time because not ev‐ erything needs to be responsive. Instead of encouraging developers to remove this feature, the authors of Bootstrap opted that it was best to enable it as needed. What is Responsive Design? Responsive design is a method for taking all of the existing content that is on the page, and optimizing it for the device that is viewing it. For example, the desktop not only gets the normal version of the website, but might get also get a widescreen layout, op‐ timized for the larger displays that many people have attached to their computers. Tab‐ lets get an optimized layout, taking advantage of the portrait or landscape layouts of those devices. And then with phones, you can target the much narrower width of phones. To target these different widths, Bootstrap uses CSS media queries to measure the width of the browser viewport, and then using conditionals, change which parts of the stylesheets are loaded. Using the width of the browser viewport, Bootstrap can then optimize the content using a combination of ratios, widths, but mostly falls on min width and max-width properties.. At the core, Bootstrap supports five different layouts, each relying on CSS media queries. The largest layout has columns that are 70 pixels wide, contrasting the 60 pixels of the normal layout. The tablet layout brings the columns to 42 pixels wide, and when nar‐ rower then that, each column goes fluid, meaning the columns are stacked vertically and each column is the full width of the device. Table 1-2. Responsive Media Queries Label Layout width Column width Gutter width Large display 1200px and up 70px 30px Default 980px and up 60px 20px Portrait Tablets 768px and above 42px 20px Phones to Tablets 767px and below Fluid columns, no fixed widths Phones 480px and below Fluid columns, no fixed widths To add custom CSS based on the media query, you can either include all rules in one CSS file, via the media queries below, or use entirely different CSS files. CSS media queries in the CSS stylesheet. 8 | Chapter 1: Bootstrap Scaffolding /* Large desktop */ @media (min-width: 1200px) { ... } /* Portrait tablet to landscape and desktop */ @media (min-width: 768px) and (max-width: 979px) { ... } /* Landscape phone to portrait tablet */ @media (max-width: 767px) { ... } /* Landscape phones and down */ @media (max-width: 480px) { ... } For a larger site, you might want to separate them into separate files. In the HTML file, you can call them with the link tag in the head of your document. This is useful for keeping file sizes smaller, but does potentially increase the HTTP requests if being re‐ sponsive. CSS media queries via the link tag in the HTML . Helper Classes Bootstrap also includes a handful of helper classes for doing responsive development. It would be best practice to use these sparingly. A couple of use cases that I have seen involve loading custom elements based on certain layouts. Perhaps you have a really nice header on the main layout, but on mobile you want to pare it down, leaving only a few of the elements. In this scenario, you could use the .hidden-phone class to hide either parts, or entire dom elements from the the header. Table 1-3. Media Queries Helper Classes Class Phones Tablets Desktops .visible-phone Visible Hidden Hidden .visible-tablet Hidden Visible Hidden .visible-desktop Hidden Hidden Visible .hidden-phone Hidden Visible Visible .hidden-tablet Visible Hidden Visible .hidden-desktop Visible Visible Hidden Regarding mobile development, there are two major ways that you could look at doing development. The mantra that a lot of people are shouting now, is that you should start with mobile, build to that platform, and let the desktop follow. Bootstrap almost forces the opposite, where you would create a full featured desktop site that “just works”. Responsive Design | 9 If you are looking for a strictly mobile framework, Bootrap is still a great resource. 10 | Chapter 1: Bootstrap Scaffolding CHAPTER 2 Bootstrap CSS At the core of Bootstrap are a set of basic HTML elements that have been styled in such a way that allow for easy enhancement via classes and user styles. Typography Starting with Typography, with the default font stack, Bootstrap uses Helvetica Neue, Helvetica, Arial, and sans-serif. These are all standard fonts, and included as defaults on all major cpmputers, falling back to sans-serif, the catch all to tell the browser to use the default font that the user has decided. All body copy has the font-size set at 14 pixels, with the line-height set at 20 pixels. The

tag has a margin-bottom of 10 pixels, or half the line-height. Headings 11 Figure 2-1. Headings All six standard heading levels have been styled in Bootstrap, with the

at 36 pixels high, and the

down to 12 pixels in height (for reference, body text is 14 pixels in height by default). In addition, to add an inline sub-heading to any of the headings, simply add around any of the elements, and you will get smaller text, in a lighter color. In the case of the

, the small text is 24 pixels tall, normal font weight (i.e., not bold), and gray instead of black. h1 small { font-size:24px; font-weight:normal; line-height:1; color:#999; } Lead body copy To add some emphasis to a paragraph, add class="lead". This will give you larger font size, lighter weight, and a taller line height. This is usually used for the first few para‐ graphs in a section, but can really be used anywhere.

Bacon ipsum dolor sit amet tri-tip pork loin ball tip frankfurter swine boudin me12 | Chapter 2: Bootstrap CSS Figure 2-2. Lead Body Copy Classes Emphasis In addition to using the tag within headings, as discussed above, you can also use it with body copy. When is applied to body text, the font shrinks to 85% of its original size. Bold To add emphasis to text, simply wrap it in a tag. This will add font-weight bold to the selected text. Italics For italics, wrap your content in the tag. “em” derives from the word “emphasis”, and is meant to add stress to your text. You might be thinking to yourself, why not just use the or tags instead of or . In HTML5, is meant to highlight words or phrases without conveying additional importance—for example, key terms or names—while is mostly for voice, technical terms, internal dialogue, etc. For more information about the semantic changes to and , check out W3.org’s article. Emphasis classes Along with and , Boootstrap offers a few other classes that can be used to provide emphasis. These could be applied to paragraphs, or spans. Emphasis Classes.

This content is muted

This content carries a warning class

This content carries an error class

This content carries an info class

Typography | 13

This content carries a success class

This content has emphasis, and can be bold

Figure 2-3. Emphasis Classes Abbreviations The HTML element provides markup for abbreviations or acronyms, like WWW or HTTP. By marking up abbreviations, you can give useful information to browsers, spell checkers, translation systems or search engines. Bootstrap styles elements with a light dotted border along the bottom, and reveals the full text on hover (as long as you add that text to the title attribute). Abbreviation Example. RSS Figure 2-4. Emphasis Classes 14 | Chapter 2: Bootstrap CSS Add .initialism to an for a slightly smaller font size. Abbreviation Example. RSS Figure 2-5. Emphasis Classes Addresses Adding
elements to your page can help screen readers and search engines locate any physical addresses and phone numbers in the text. It can also be used to mark up email addresses. Since the
defaults to display:block; you’ll need to use
tags to add line breaks to the enclosed address text (for example, to split the street address and city onto separate lines). Address Markup.
O'Reilly Media, Inc.
1005 Gravenstein HWY North
Sebastopol, CA 95472
P: (707) 827-7000
Jake Spurlock
[email protected]
Typography | 15 Figure 2-6. Address Tag Blockquotes To add blocks of quoted text to your document—or for any quotation that you want to set apart from the main text flow—add the
tag around the text. For best results, and for line breaks, wrap each subsection in a

tag. Bootstrap’s default styling indents the text, and adds a thick grey border along the left side. To identify the source of the quote, add the tag, and inside that, add the source’s name wrapped in a tag. When you put it all together, you get something that looks like this: Figure 2-7. Basic Blockquote Blockquote Markup.

That this is needed, desperately needed, is indicated by the incredible uptake of Boot Developer of RSS, Dave Winer

16 | Chapter 2: Bootstrap CSS If you want a
with content that is right-aligned, simply add .pull-right to the tag. In addition to the right-aligned text, the entire blockquote is floated to the right. This creates nice pull-quotes in your content. Figure 2-8. Pull-Right Blockquote Lists Bootstrap offers support and styling for the three main list types that HTML offers: ordered, unordered, and definition lists. An unordered list is a list that doesn’t have any particular order, and is traditionally styled with bullets. Unordered List Unordered List Markup.

Favorite Outdoor Activites

  • Backpacking in Yosemite
  • Hiking in Arches
    • Delicate Arch
    • Park Avenue
  • Biking the Flintstones Trail
Typography | 17 Figure 2-9. Unordered List Example If you have an ordered list that you would like to remove the bullets from, add class="unstyled" to the opening
    tag. Personally, I hold a strong aversion to using the
    tag, and when I want a single spaced line break, I place each line in an unstyled unor‐ dered list. As an example, you might want a condensed address box, like the illustration above, you could have each line as a
  • . In my mind, this is the more semantic way to markup the text. Ordered List An ordered list is a list that falls in some sort of sequential order, and is prefaced by numbers rather then bullets. This is handy when you want to build a list of numbered items, like a task list, guide items, or even a list of comments on a blog post. Ordered List Markup.

    Self-Referential Task List

    1. Turn off the internet.
    2. Write the book
    3. ... Profit?
Figure 2-10. Ordered List Example 18 | Chapter 2: Bootstrap CSS Definition List The third type of list you get with Bootstrap is the definition list. The definition list differs from the ordered and unordered list in that instead of just having a block level
  • element, each list item can consist of both the
    and the
    elements.
    stands for “definition term,” and like a dictionary, this is the term (or phrase) that is being defined. Subsequently, the
    is the definition of the
    . A lot of times in markup, you will see people using headings inside an unordered list. This works, but maybe isn’t the most semantic way to markup the text. A better idea would be to create a
    and then style the
    and
    as you would the heading and the text. That being said, out of the box, Bootstrap offers some clean default styles, and an option for a side-by-side layout of each definition. Definition List Markup.

    Common Electronics Parts

    LED
    A light-emitting diode (LED) is a semiconductor light source.
    Servo
    Servos are small, cheap, mass-produced actuators used for radio control and small rob
    Figure 2-11. Definition List Example To change the
    to a horizontal layout, with the
    on the left side, and the
    on the right, simply add class="dl-horizontal" to the opening tag. Figure 2-12. Horizontal Definition List Example Typography | 19 Horizontal description lists will truncate terms that are too long to fit in the left column with text-overflow. Additionally, in narrower view‐ ports, they will automatically change to the default stacked layout. Code There are two different key ways to display code with Bootstrap. The first is the tag, and the second is with the
     tag. Generally, if you are going to be displaying code inline, then you should use the  tag, but if it needs to be displayed as a standalone block element, or if it has multiple lines, then you should use the 
     tag. 
    

    Instead of always using divs, in HTML5, you can use new elements like <section> <article> <h1>Article Heading</h1> </article>

    Make sure that when you use the
     and  tags, you use the 
    unicode variants for the opening and closing tags. < and > 
    Tables 
    One of my favorite parts of Bootstrap is the nice way that tables are handled. I do a lot of work looking at and building tables, and the clean layout is great feature that’s included in Bootstrap right off the bat. Bootstrap supports the following elements: 
    Table 2-1. Table Elements Bootsrap Supports 
    Tag Description 
     Wrapping element for displaying data in a tabular format 
     Container element for table header rows () to label table columns 
     Container element for table rows () in the body of the table 
     Container element for a set of table cells (. This is done via the CSS :nth-child selector which is not available on Internet Explorer 7-8. 
    Tables | 21
    
    
    
    
    Figure 2-14. Striped Table Class 
    Bordered Table 
    If you add the .table-bordered class, you will get borders surrounding every element, and rounded corners around the entire table. 
    
    
    
    
    Figure 2-15. Bordered Table Class 
    Hover Table 
    If you add the .table-hover class, when you hover over a row, a light grey background will be added to rows while the user hovers over them. 
    
    
    
    
    Figure 2-16. Hover Table Class 
    Condensed Table 
    If you add the .table-condensed class, padding is cut in half on rows to condense the table. Useful if you want denser information. 
    22 | Chapter 2: Bootstrap CSS
    
    
    
    
    Figure 2-17. Condensed Table Class 
    Table Row Classes 
    If you want to style the table rows, you could add the following classes to change the background color. 
    Table 2-2. Optional Table Row Classes 
    Class Description Background Color 
    .success Indicates a successful or positive action. Green 
    .error Indicates a dangerous or potentially negative action. Red 
    .warning Indicates a warning that might need attention. Yellow 
    .info Used as an alternative to the default styles. Blue 
    
    
    
    
    Figure 2-18. Table Row Classes Example 
    Forms 
    Another one of the highlights of using Bootstrap is the attention that is paid to forms. As a web developer, one of my least favorite things to do is style forms. Bootstrap makes it easy to do with the simple HTML markup and extended classes for different styles of forms. 
    The basic form structure comes styled in Bootstrap, without needing to add any extra helper classes. If you use the placeholder, it is only supported in newer browsers. In older ones, no text will be displayed. 
    Forms | 23
    
    
    
    
    Figure 2-19. Basic Form 
    Basic Form Structure.  
    
    Legend Example block-level help text here.
    Optional Form Layouts With a few helper classes, you can dynamically update the layout of your form. Bootstrap comes with a few preset styles you can use. Search Form Add .form-search to the form tag, and then .search-query to the for an input box with rounded corners, and an inline submit button. Basic Form Structure. 24 | Chapter 2: Bootstrap CSS Figure 2-20. Search Form Inline Form To create a form where all of the elements are inline, and labels are along side, add the class .form-inline to the form tag. To have the label and the input on the same line, use the horizontal form below. Inline Form Code. Figure 2-21. Inline Form Example Horizontal Form Bootstrap also comes with a pre-baked horizontal form; this one stands apart from the others not only in the amount of markup, but also in the presentation of the form. Traditionally you’d use a table to get a form layout like this, but Bootstrap manages to do it without. Even better, if you’re using the responsive CSS, the horizontal form will automatically adapt to smaller layouts by stacking the controls vertically. To create a form that uses the horizontal layout, do the following: • Add a class of form-horizontal to the parent element • Wrap labels and controls in a div with class control-group • Add a class of control-label to the labels • Wrap any associated controls in a div with class controls for proper alignment Forms | 25 Figure 2-22. Horizontal Form Example Horizontal Form Code.
    Supported Form Controls Bootstrap natively supports the most common form controls. Chief among them, in put, textarea, checkbox and radio, and select. Inputs The most common form text field is the input—this is where users will enter most of the essential form data. Bootstrap offers support for all native HTML5 input types: text, password, datetime, datetime-local, date, month, time, week, number, email, url, search, tel, and color. 26 | Chapter 2: Bootstrap CSS Figure 2-23. Input Example Input Code. Both input and textarea default to a nice blue glow when in the :ac tive state. Textarea The textarea is used when you need multiple lines of input. You’ll find you mainly modify the rows attribute, changing it to the number of rows that you need to support (fewer rows = smaller box, more rows = bigger box). Figure 2-24. Both the :active, and the default textarea Textarea Example. Checkboxes and radios Checkboxes and radio buttons are great for when you want users to be able to choose from a list of preset options. When building a form, use checkbox if you want the user to select any number of options from a list, and radio if you want to limit them to just one selection. Forms | 27 Figure 2-25. Radio and Checkbox example Radio and Checkbox Code Example. Figure 2-26. Inline Checkboxes If you want multiple checkboxes to appear on the same line together, simply add the .inline class to a series of checkboxes or radios. 28 | Chapter 2: Bootstrap CSS Selects A select is used when you want to allow the user to pick from multiple options, but by default it only allows one. It’s best to use Extending Form Controls In addition to the basic form controls listed in the previous section, Bootstrap offers a few other form components to complement the standard HTML form elements; for example, it lets you easily prepend and append content to inputs. Prepended and Appended Inputs By adding prepended and appended content to an input field, you can add common elements to the text users input, like the dollar symbol, the @ for a Twitter username or anything else that might be common for your application interface. To use, wrap the input in a div with class input-prepend (to add the extra content before the user input) Forms | 29 or input-append (to add it after). Then, within that same
    , place your extra content inside a with an add-on class, and place the either before or after the element. Figure 2-28. Prepend and Append Example Prepend and Append Code Example.
    @
    .00
    If you combine both of them, you simply need to add both the .input-prepend and .input-append classes to the parent
    . Figure 2-29. Using both the append and prepend Append and Prepend Code Example.
    $ .00
    Rather then using a , you can instead use
    If you are appending a button to a search form, you will get the same nice rounded corners that you would expect. Figure 2-31. Append Button to Search Form
    Form Control Sizing With the default grid system that is inherent in Bootstrap, you can use the .span* system for sizing form controls. In addition to the span column-sizing method, you can also use a handful of classes that take a relative approach to sizing. If you want the input to act as a block level element, you can add .input-block-level and it will be the full width of the container element. Figure 2-32. Block Level Input Forms | 31 Relative Input Controls In future versions of Bootstrap, these input classes will be altered to match the button sizes. For example, .input-large will increase the padding and font-size of an input. Grid Sizing You can use any .span from .span1 to .span12 for form control sizing. 32 | Chapter 2: Bootstrap CSS If you want to use multiple inputs on a line, simply use the .controls-row modifier class to apply the proper spacing. It floats the inputs to collapse the white space, and set the correct margins, and like the .row class, it also clears the float. Figure 2-33. Control Row
    ... Uneditable Text If you want to present a form control, but not have it editable, simple add the class .uneditable-input. Forms | 33 Figure 2-34. Uneditable Input Some value here Form Actions At the bottom of a horizontal-form you can place the form actions. Then inputs will correctly line up with the floated form controls. Figure 2-35. Form Controls
    Help Text Bootstrap form controls can have either block or inline text that flows with the inputs. Figure 2-36. Inline Help Inline help text Figure 2-37. Block Help A longer block of help text that breaks onto a new li34 | Chapter 2: Bootstrap CSS Form Control States In addition to the :focus state, Bootstrap offers styling for disabled inputs, and classes for form validation. Input Focus When an input receives :focus, that is to say, a user clicks into the input, or tabs into it, the outline of the input is removed, and a box-shadow is applied. I remember the firs time that I saw this on Twitter’s site, it blew me away, and I had to dig into the code to see how they did it. In WebKit, this accomlished in the following manner: input { -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); -webkit-transition: box-shadow linear 0.2s; } input:focus { -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6); } The has a small inset box-shadow, this gives the appearence that the input sits lower then the page. When :focus is applied, an 8px light blue code is applied. The webkit-transition tells the browser to apply the effect in a linera manner over 0.2 seconds. Nice and subtle, a great effect. Figure 2-38. Focused Input Disabled Input If you need to disable an input, simply add the disabled attribute to not only disable it, but change the styling, and the mouse cursor when it hover over the element. Figure 2-39. Disabled Input
    Something may have gone wrong
    Please correct the error
    Woohoo!
    Buttons One of my favorite features of Bootstrap is the way that buttons are styled. Dave Winer, inventor of RSS, and big fan of Bootstrap has this to say about it: That this is needed, desperately needed, is indicated by the incredible uptake of Bootstrap. I use it in all the server software I’m working on. And it shows through in the templating language I’m developing, so everyone who uses it will find it’s “just there” and works, any 36 | Chapter 2: Bootstrap CSS time you want to do a Bootstrap technique. Nothing to do, no libraries to include. It’s as if it were part of the hardware. Same approach that Apple took with the Mac OS in 1984. — Dave Winer scripting.com I like to think that Bootstrap is doing that, unifying the web, and allowing a unified experience of what an interface can look like across the web. With the advent of Boot‐ strap, you can spot the sites that have taken it up ususally first by the buttons that they use. A grid layout, and many of the other features fade into the background, but buttons, forms and other uniying elements are a key part of Bootstrap. Maybe I’m the only person that does this, but when I come across a site that is using Bootstrap, I want to give a high five to whomever answers the webmaster email at that domain, as they probably just get it. It reminds me of a few years ago I would do the same thing when I would see wp content in the HTML of sites that I would visit. Now, buttons, and links can all look alike with Bootstrap, anything that is given that class of btn will inherit the default look of a grey button with rounded corners. Adding extra classes will add colors to the buttons. Table 2-3. Button Color Examples Buttons Class Description btn Standard gray button with gradient btn btn-primary Provides extra visual weight and identifies the primary action in a set of buttons btn btn-info Used as an alternative to the default styles btn-success Indicates a successful or positive action btn btn-warning Standard gray button with gradient btn btn-danger Indicates a dangerous or potentially negative action btn btn-inverse Alternate dark gray button, not tied to a semantic action or use btn btn-link Deemphasize a button by making it look like a link while maintaining button behavior Buttons | 37 There are issues with Internet Explorer 9 not cropping background gradients on rounded corners, so buttons aren’t shown. Also, Internet Exporer doesn’t work well with disabled button elements. The rendered text is gray with a nasty text-shadow that hasn’t been fixed. Button Sizes If you need larger or smaller buttons, simply add .btn-large, .btn-small, or .btn mini to links or buttons. Figure 2-41. Different Button Sizes

    If you want to create buttons that display like a block level element, simply add the btn block class. These buttons will display at 100% width. 38 | Chapter 2: Bootstrap CSS Figure 2-42. Block Level Button Disabled Button Styling For anchor elements, simply add the class of .disabled to the tag, and the link will drop back in color, and will lose the gradient. The .disabled class is being used much like the .active class. So, no .btn prefix, and remember, this is only for looks, to truly disable the link, you will want to use some javascript to really disable the link. Figure 2-43. Disabled Link Primary linkLink For a button, simply add the disabled attribute to the button. This will actually disable the button, so javascript is not directly needed. Figure 2-44. Disabled Button Buttons | 39 Images Images have three classes to apply some simple styles. They are .img-rounded that adds border-radius:6px to give the image rounded corners, .img-circle that adds makes the entire image a circle by adding border-radius:500px making the image round, and lastly, ing-polaroid, that adds a bit of padding and a grey border. Figure 2-45. Images Icons Bootstrap bundles 140 icons into one sprite that can be used with buttons, links, navi‐ gation, and and form fields. The icons are provided by Glyphicons. 40 | Chapter 2: Bootstrap CSS Glyphicon Attribution Users of Bootstrap are fortunate to use the Glyphicons free of use on Bootstrap projects. The developers have asked that you use a link back to Glyphicons when practical. Glyphicons Halflings are normally not available for free, but an arrangement between Bootstrap and the Glyphicons creators have made this possible at no cost to you as de‐ Icons | 41 velopers. As a thank you, we ask you to include an optional link back to Glyphicons whenever practical. — Bootstrap Documentation http://getbootstrap.com Usage To use the icons, simply use an tag with the namespaced .icon- class. For example, if you wanted to use the edit icon, you would simply add the .icon-edit class to the tag. If you want to use the white icon, simply add the .icon-white class to the tag. Button Groups Using button groups, conbined with icons, you can create nice interface elements with minimal markup.
    Navigation When you are using icons next to a string of text, make sure to add a space to provide the proper alignment of the image. More of navigation code will be covered in the next chapter. Icons | 43 CHAPTER 3 Bootstrap Layout Components In addtion to all of the markup provided in the previous chapter, Bootstrap provides a toolkit of flexible components that can be used in designing application interfaces, web features and more. Each of the plugins are available in a seperate Javascript file, com‐ bined all together, or, using the Bootstrap customizer, you can pick and choose which plugins you want. Personally, on the projects that I build, I lump them all together. That way I have options. Dropdown Menus Dropdown menus are a toggleable, contextual menu for displaying links in a list format. The dropdowns can be used on a variety of different elements, navs, buttons, and more. You can have a single dropdown, or extend the dropdown into another sub-menu. Figure 3-1. Basic Dropdown Menu Options Right align the dropdown Add .pull-right to a .dropdown-menu to right-align the dropdown menu to the parent object. If you would like to add a second layer of dropdowns, simply add .dropdown submenu to any
  • in an existing dropdown menu for automatic styling. Dropdown Submenu Button Groups Button groups allow multiple buttons to be stacked together. This is useful like the example below when you want to place items like alignment buttons together. Simply, to create a button group, simply wrap a series of anchors or buttons with a class of .btn with a
    that has .btn-group as a class. 46 | Chapter 3: Bootstrap Layout Components Figure 3-2. Inline Button Group Inline Button Group Code Example.
    If you have multiple button groups that you want to align on a single line, wrap multiple .btn-group with .btn-toolbar. For more information about using icons with buttons, follow the examples in chapter 2. Figure 3-3. Button Toolbar Button Toolbar Code Example.
    To make the buttons stack, simply add .btn-group-vertical to the .btn-group class. Button Groups | 47 Figure 3-4. Vertical Button Group Vertical Button Group Code.
    ...
    Button Groups as Radio and Checkboxes To have the checkboxes function as radio buttons where only one can be selected at a time, or checkboxes where multiple can be selected, you simply need to add some extra markup and the Bootsrap JavaScript will provide the rest. This will be covered in detail in chapter 4. To use a button with a dropdown, they must be individually wrapped in their own btn-group within a btn-toolbar for proper rendering. Buttons With Dropdowns To add a dropdown to a button, simply wrap a button and a dropdown menu in a .btn group. You can also use a to act as an indicator that the button is a dropwdown. Figure 3-5. Button with a Dropdown 48 | Chapter 3: Bootstrap Layout Components Button Dropdown Code. You can use the dropdowns with any button size, .btn-large .btn, .btn-small and .btn-mini. Figure 3-6. Button Dropdown Sizes Split Button Dropdowns Using the same general styles of the dropdown button, but adding a primary action along with the dropdown, split buttons have the primary action on the left, and the a toggle on the right for the dropdown. Figure 3-7. Split Button Dropdown Split Button Dropdown Code Example. Buttons With Dropdowns | 49
    http://jsfiddle.net/vSHkJ/embedded/result/ Dropup Menus Menus can also be built to dropup, rather then down. To make this change, simply add .dropup to the .btn-group container. To have the button pullup from the right hand side, add .pull-right to the .dropdown-menu. Take notice, the caret is now poin‐ ted up, as the menu will be going up instead of down. Figure 3-8. Dropup Menu Dropup Menu Code Example.
    http://jsfiddle.net/DyfSZ/3/embedded/result/ 50 | Chapter 3: Bootstrap Layout Components Navigation Elements Bootstrap provides a few different opportunities for styling naviagation elements. All of them share the same markup and base class .nav. Bootstrap also provides a helper class, .active. In principal, it generally adds distinction to the current element, and sets it apart from the the rest of the navigation elements. You could add this class to the home page links, or add it to the links of the page that you are currently on. Tabular Navigation To create a tabbed navigation menu, start with a basic unordered list with the base class of .nav and add .nav-tabs. Figure 3-9. Tabbed Navigation Tabbed Navigation Code Example. Basic Pills Navigation To turn the tabs into pills, instead of using the .nav-tabs use .nav-pills. Figure 3-10. Tabbed Navigation Tabbed Navigation Code Example. Disabled Class For each of the .nav classes, if you add the .disabled class, it will create gray link that also disables the hover state. The link is still clickable unless the href is removed, with javascript or some other method. Figure 3-11. Disabled Navigation Disabled Navigation Code Example. Stackable Navs Both tabs and pills are horizontal by default, to make them stackable, just add the .nav stacked class to make them appear vertically stacked. Figure 3-12. Stacked Tabs Stacked Tabs Code Example. 52 | Chapter 3: Bootstrap Layout Components Figure 3-13. Stacked Pills Stacked Pills Code Example. Dropdowns Navigation menus share a similir syntax to dropdown menus. By default, you have a list item that has an anchor that works in conjuntion with some data- attributes to trigger an unodered list with a .dropdown-menu class. Figure 3-14. Tabbed Navigation with a Dropdown Menu Tabbed Navigation Dropdown Code Example. To do the same thing with pills, simply swap the .nav-tabs class with .nav-pills. Figure 3-15. Pill Navigation with Dropdowns Pill Navigation Dropdown Code Example. Navigation Lists Navigation lists are useful when you need to display a group of navigation links. This type of interface element is common when building admin interfaces in websites. In the MAKE admin interface, I have one of these on the sidebar of every page with quick links to common pages. A form of this is what that Bootstrap developers use for their docu‐ mentation. Like all of the lists that we have discusses thus far, this is simply an unordered list with the .nav class, and to give it it’s specific styling, we add the .nav-list class. 54 | Chapter 3: Bootstrap Layout Components Figure 3-16. Navigation List Navigation List Code Example. Horizontal Divider To create a divider, much like an
    , use an empty
  • with a class of .divider. Horizontal Divider. Tabbable Navigation Not only can you create a tabbed navigation, but by using the JavaScript plugin, you can also add some interaction by making them tab able to open different windows of content. To make navigation tabs tabbable, create a .tab-pance with a unique ID for every tab, and then wrap them in `.tab-content. Navigation Elements | 55 Figure 3-17. Tabbable Navigation Example Tabble Navigation Code Example.

    Bacon ipsum dolor sit amet jerky flank...

    Beef ribs, turducken ham hock...

    http://jsfiddle.net/JUqAT/embedded/result/ If you want to make the tabs fade when switching, add .fade to each .tab-pane. Tab Position The tabs are fully positionable, you can have them above, below, or on the sides of the content. Figure 3-18. Bottom Tabs Bottom Tab Code Example.
    56 | Chapter 3: Bootstrap Layout Components

    I'm in section A.

    I'm in section B.

    I'm in section C.

    Tabs on the left get the .tabs-left class. Figure 3-19. Left Tabs Left Tab Code Example.

    I'm in section A.

    I'm in section B.

    I'm in section C.

    Tabs on the right get the .tabs-right class. Navigation Elements | 57 Figure 3-20. Right Tabs Right Tab Code Example.

    I'm in section A.

    I'm in section B.

    I'm in section C.

    As a footnote here to the tabbable elements, you can use the markup here to control a varierty of things, perhaps outside of the scope of the default usage mechanism. On MAKE’s site, I used this to control the navigation, and subnavigation. When you click on the navigation menu, the sub navigation would change and show different links. Navbar The Navbar is a nice feature, and one of the prominant features of Bootstrap sites. At the core, the navbar includes styling for site names, and basic navigation. It can later be extended by adding form specific controls, and specialized dropdowns. To be sure that the navbar is constrained to the width of the content of the page, either place it inside of a .span12 or the .container class. 58 | Chapter 3: Bootstrap Layout Components Figure 3-21. Basic Navbar Example Basic Navbar Code Example. In the code above, note the .brand class, this will give the text a lighter font-weight and slightly larger size. Brand Class Example. Project name Nav Links To add links to the navbar, simply add an unordered list with the class of .nav. If you want to add a divider to your links, you can do that by adding an empty list-item with a class of .divider-vertical. Figure 3-22. Nav Links Navbar Links Code Example. Navbar | 59 Forms Instead of using the default, class based forms from chapter 2, forms that are in the navbar use the .navbar-form class. This ensures that the forms margins are properly set, and match the nav stylings. Of note, .pull-left, and .pull-right helper classes may help move the form in the proper position. Figure 3-23. Default Navbar Form Default Navbar Form Styling.
  • or ) that appears on a single row Default table cell Special table cell for column (or row, depending on scope and placement) labels. Must be used within a
    Description or summary of what the table holds, especially useful for screen readers If you want a nice basic table style with just some light padding and horizontal dividers only, add the base class of .table to any table. The basic layout has a top border on all of the
    elements. 20 | Chapter 2: Bootstrap CSS Figure 2-13. Basic Table Class Table Base Class Example.
    ...
    ... ...
    ... ...
    Optional Table Classes With the base table markup, and adding the .table class, there are few additional clases that you can add to style the markup. There are three classes, .table-striped, .table bordered, .table-hover, and .table-condensed. Striped Table By adding the .table-striped class, you will get stripes on rows within the