{{_i}}Customize and extend Bootstrap with LESS, a CSS preprocessor, to take advantage of the variables, mixins, and more used to build Bootstrap's CSS.{{/i}}
{{_i}}Bootstrap is made with LESS at it's core, a dynamic stylesheet language created by Alexis Sellier. It makes developing systems-based CSS faster, easier, and more fun.{{/i}}
{{_i}}As an extension of CSS, LESS includes variables, mixins for reusable snippets of code, operations for simple math, nesting, and even color functions.{{/i}}
{{_i}}Visit the official website at http://lesscss.org to learn more.{{/i}}
{{_i}}Managing colors and pixel values in CSS can be a bit of a pain, usually full of copy and paste. Not with LESS though—assign colors or pixel values as variables and change them once.{{/i}}
{{_i}}Those three border-radius declarations you need to make in regular ol' CSS? Now they're down to one line with the help of mixins, snippets of code you can reuse anywhere.{{/i}}
{{_i}}Make your grid, leading, and more super flexible by doing the math on the fly with operations. Multiple, divide, add, and subtract your way to CSS sanity.{{/i}}
{{_i}}Variable{{/i}} | {{_i}}Value{{/i}} | {{_i}}Usage{{/i}} |
---|---|---|
@linkColor |
#08c | {{_i}}Default link text color{{/i}} |
@linkColorHover |
darken(@linkColor, 15%) |
{{_i}}Default link text hover color{{/i}} |
{{_i}}Variable{{/i}} | {{_i}}Value{{/i}} |
---|---|
@black |
#000 |
@grayDarker |
#222 |
@grayDark |
#333 |
@gray |
#555 |
@grayLight |
#999 |
@grayLighter |
#eee |
@white |
#fff |
{{_i}}Variable{{/i}} | {{_i}}Value{{/i}} |
---|---|
@blue |
#049cdb |
@green |
#46a546 |
@red |
#9d261d |
@yellow |
#ffc40d |
@orange |
#f89406 |
@pink |
#c3325f |
@purple |
#7a43b6 |
{{_i}}Variable{{/i}} | {{_i}}Value{{/i}} |
---|---|
@gridColumns |
12 |
@gridColumnWidth |
60px |
@gridGutterWidth |
20px |
@siteWidth |
(@gridColumns * @gridColumnWidth) + (@gridGutterWidth * (@gridColumns - 1)) |
{{_i}}Variable{{/i}} | {{_i}}Value{{/i}} | |
---|---|---|
@baseFontSize |
13px | |
@baseFontFamily |
"Helvetica Neue", Helvetica, Arial, sans-serif |
|
@baseLineHeight |
18px |
@primaryButtonColor |
@blue |
{{_i}}Bootstrap was built with Preboot, an open-source pack of mixins and variables to be used in conjunction with Less, a CSS preprocessor for faster and easier web development.{{/i}}
{{_i}}Check out how we used Preboot in Bootstrap and how you can make use of it should you choose to run Less on your next project.{{/i}}
{{_i}}Use this option to make full use of Bootstrap’s Less variables, mixins, and nesting in CSS via javascript in your browser.{{/i}}
<link rel="stylesheet/less" href="less/bootstrap.less" media="all" /> <script src="js/less-1.1.3.min.js"></script>
{{_i}}Not feeling the .js solution? Try the Less Mac app or use Node.js to compile when you deploy your code.{{/i}}
{{_i}}Here are some of the highlights of what’s included in Twitter Bootstrap as part of Bootstrap. Head over to the Bootstrap website or Github project page to download and learn more.{{/i}}
{{_i}}Variables in Less are perfect for maintaining and updating your CSS headache free. When you want to change a color value or a frequently used value, update it in one spot and you’re set.{{/i}}
// Links @linkColor: #8b59c2; @linkColorHover: darken(@linkColor, 10); // Grays @black: #000; @grayDark: lighten(@black, 25%); @gray: lighten(@black, 50%); @grayLight: lighten(@black, 70%); @grayLighter: lighten(@black, 90%); @white: #fff; // Accent Colors @blue: #08b5fb; @green: #46a546; @red: #9d261d; @yellow: #ffc40d; @orange: #f89406; @pink: #c3325f; @purple: #7a43b6; // Baseline grid @basefont: 13px; @baseline: 18px;
{{_i}}Less also provides another style of commenting in addition to CSS’s normal /* ... */
syntax.{{/i}}
// This is a comment /* This is also a comment */
{{_i}}Mixins are basically includes or partials for CSS, allowing you to combine a block of code into one. They’re great for vendor prefixed properties like box-shadow
, cross-browser gradients, font stacks, and more. Below is a sample of the mixins that are included with Bootstrap.{{/i}}
#font { .shorthand(@weight: normal, @size: 14px, @lineHeight: 20px) { font-size: @size; font-weight: @weight; line-height: @lineHeight; } .sans-serif(@weight: normal, @size: 14px, @lineHeight: 20px) { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: @size; font-weight: @weight; line-height: @lineHeight; } ... }
#gradient { ... .vertical (@startColor: #555, @endColor: #333) { background-color: @endColor; background-repeat: repeat-x; background-image: -khtml-gradient(linear, left top, left bottom, from(@startColor), to(@endColor)); // Konqueror background-image: -moz-linear-gradient(@startColor, @endColor); // FF 3.6+ background-image: -ms-linear-gradient(@startColor, @endColor); // IE10 background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, @startColor), color-stop(100%, @endColor)); // Safari 4+, Chrome 2+ background-image: -webkit-linear-gradient(@startColor, @endColor); // Safari 5.1+, Chrome 10+ background-image: -o-linear-gradient(@startColor, @endColor); // Opera 11.10 background-image: linear-gradient(@startColor, @endColor); // The standard } ... }
{{_i}}Get fancy and perform some math to generate flexible and powerful mixins like the one below.{{/i}}
// Griditude @gridColumns: 16; @gridColumnWidth: 40px; @gridGutterWidth: 20px; @siteWidth: (@gridColumns * @gridColumnWidth) + (@gridGutterWidth * (@gridColumns - 1)); // Make some columns .columns(@columnSpan: 1) { width: (@gridColumnWidth * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1)); }
{{_i}}After modifying the .less
files in /lib/, you'll need to recompile them in order to regenerate the bootstrap-*.*.*.css and bootstrap-*.*.*.min.css files. If you're submitting a pull request to GitHub, you must always recompile.{{/i}}
{{_i}}Method{{/i}} | {{_i}}Steps{{/i}} |
---|---|
{{_i}}Node with makefile{{/i}} |
{{_i}}Install the LESS command line compiler with npm by running the following command:{{/i}} $ npm install less {{_i}}Once installed just run {{_i}}Additionally, if you have watchr installed, you may run |
{{_i}}Javascript{{/i}} |
{{_i}}Download the latest Less.js and include the path to it (and Bootstrap) in the <link rel="stylesheet/less" href="/path/to/bootstrap.less"> <script src="/path/to/less.js"></script> {{_i}}To recompile the .less files, just save them and reload your page. Less.js compiles them and stores them in local storage.{{/i}} |
{{_i}}Command line{{/i}} |
{{_i}}Install the LESS command line tool via Node and run the following command:{{/i}} $ lessc ./lib/bootstrap.less > bootstrap.css {{_i}}Be sure to include |
{{_i}}Unofficial Mac app{{/i}} |
{{_i}}The unofficial Mac app watches directories of .less files and compiles the code to local files after every save of a watched .less file.{{/i}} {{_i}}If you like, you can toggle preferences in the app for automatic minifying and which directory the compiled files end up in.{{/i}} |
Crunch | {{_i}}Crunch is a great looking LESS editor and compiler built on Adobe Air.{{/i}} |
CodeKit | {{_i}}Created by the same guy as the unofficial Mac app, CodeKit is a Mac app that compiles LESS, SASS, Stylus, and CoffeeScript.{{/i}} |
Simpless | {{_i}}Mac, Linux, and PC app for drag and drop compiling of LESS files. Plus, the source code is on GitHub.{{/i}} |