Bootstrap
Jake Spurlock
Beijing Cambridge Farnham Kln Sebastopol Tokyo
Special Upgrade Offer
If you purchased this ebook directly from oreilly.com, you have the following benefits:
DRM-free ebooksuse your ebooks across devices without restrictions or limitations
Multiple formatsuse on your laptop, tablet, or phone
Lifetime access, with free updates
Dropbox syncingyour files, anywhere
If you purchased this ebook from another retailer, you can upgrade your ebook to take advantage of all these benefits for just $4.99. to access your ebook upgrade.
Please note that upgrade offers are not available from sample content.
Foreword
Dave Winer
editor, Scripting News, January 2013, New York
I was a software developer before Mac existed, so I remember how the tech industry reacted to it. For the most part, the community reacted with a fair amount of skepticism. 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 didnt like were what made them important.
Apple realized that there is a set of things that all software has to do, so why shouldnt they all do them the same way? If they did, software would be easier to develop and debug, but more importantit would be easier to use. If there was only one way to create menus, then once a user learned how to use the menus of one app, he would already know how to use the menus of all others. The same is true with scrollbars, windows, the keyboard, the mouse, printing, and sound.
The reason programmers didnt 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 didnt take to the UI standards very well. What to do about them? Well, you adapted, thats what you did.
This is a well-known technical process called factoring. If you see yourself doing something over and over, do it one more time really well, work on the API so its easy and flexible, and thats it. You never do it again. Its how you build ever-taller buildings out of software. What was the leading edge five years ago is baked into the operating system today. Progress. Its a wonderful thing!
The same patterns are observable in the Web. In fact, its kind of sad how much of a repeat it is, how backward todays 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 the code that creates menus. Sure, my menu looks like all the others, but thats a good thing for users. There is no need to learn a second or third way to use a menu.
That this is needed, desperately needed, is indicated by the incredible uptake of Bootstrap. I use it in all the server software Im working on. And it shows through in the templating language Im developing, so everyone who uses it will find its just there and works any time you want to do a Bootstrap technique. Nothing to do; no libraries to include. Its as if it were part of the hardware. Its the 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. However, while they could have created something more compact and perhaps more elegant, it wouldnt have been 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 Weba 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 dont 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 OReilly book. Now Bootstrap has one. The author, Jake Spurlock, a web developer, has been building 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 Jakes able hands. He will show you how the Bootstrap magic works, so you too can help move the web development world forward.
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. Its 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 book is mostly for people who have a good handle on HTML/CSS and JavaScript, and are curious about building responsive sites, adding the Bootstrap JavaScript plugins, or building sites faster by using this popular open source framework.
Who This Book Is Not For
This book is not for people who get all they need out of the Bootstrap online documentation. Like a lot of people, the online docs are where I got startedbuilding my first site with Bootstrap 1.3 and then upgrading it to Bootstrap 1.4. After that, I built a big project with Bootstrap 2.0, and so on. If you are comfortable writing semantic HTML, then jumping into Bootstrap should be easy for you.
What This Book Will Do For You
If you have 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 the book follows the patterns for writing semantic HTML and CSS.
How This Book Works
This book builds a site with Bootstrap, starting at the foundation of the project and the file structure, moving up through the grid system and layout types, and 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, we move on to the JavaScript elements, such as dropdowns, the carousel, and modals, that provide the interaction for a site.
Why I Wrote This Book
Im not a Bootstrap expert hoping to create more Bootstrap experts to get a lot of work done.
Im a developer and writer who encountered Bootstrap through a post on Dave Winers blog, and I thought it would be cool to apply it to a new site that I was working on. I feel compelled to share some of what Ive learned. Im hoping that the path I followed will work for other people, probably with variations, and that a book written from a beginners perspective (and vetted by experts) will help more people find and enjoy Bootstrap.