evolutiondesign's posterous

Bootstrap, from Twitter

How to use it

Use this option to make full use of Bootstrap’s Less variables, mixins, and nesting in CSS via javascript in your browser.

  1. <link rel="stylesheet/less" href="less/bootstrap.less" media="all" />
  2. <script src="js/less-1.0.41.min.js"></script>

Not feeling the .js solution? Try the Less Mac app or use Node.js to compile when you deploy your code.

What’s included

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.

Color variables

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.

  1. // Links
  2. @linkColor: #8b59c2;
  3. @linkColorHover: darken(@linkColor, 10);
  4.  
  5. // Grays
  6. @black: #000;
  7. @grayDark: lighten(@black, 25%);
  8. @gray: lighten(@black, 50%);
  9. @grayLight: lighten(@black, 70%);
  10. @grayLighter: lighten(@black, 90%);
  11. @white: #fff;
  12.  
  13. // Accent Colors
  14. @blue: #08b5fb;
  15. @green: #46a546;
  16. @red: #9d261d;
  17. @yellow: #ffc40d;
  18. @orange: #f89406;
  19. @pink: #c3325f;
  20. @purple: #7a43b6;
  21.  
  22. // Baseline
  23. @baseline: 20px;

Commenting

Less also provides another style of commenting in addition to CSS’s normal /* ... */ syntax.

  1. // This is a comment
  2. /* This is also a comment */

Mixins up the wazoo

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.

Font stacks

  1. #font {
  2. .shorthand(@weight: normal, @size: 14px, @lineHeight: 20px) {
  3. font-size: @size;
  4. font-weight: @weight;
  5. line-height: @lineHeight;
  6. }
  7. .sans-serif(@weight: normal, @size: 14px, @lineHeight: 20px) {
  8. font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  9. font-size: @size;
  10. font-weight: @weight;
  11. line-height: @lineHeight;
  12. }
  13. .serif(@weight: normal, @size: 14px, @lineHeight: 20px) {
  14. font-family: "Georgia", Times New Roman, Times, sans-serif;
  15. font-size: @size;
  16. font-weight: @weight;
  17. line-height: @lineHeight;
  18. }
  19. .monospace(@weight: normal, @size: 12px, @lineHeight: 20px) {
  20. font-family: "Monaco", Courier New, monospace;
  21. font-size: @size;
  22. font-weight: @weight;
  23. line-height: @lineHeight;
  24. }
  25. }

Gradients

  1. #gradient {
  2. .horizontal (@startColor: #555, @endColor: #333) {
  3. background-color: @endColor;
  4. background-repeat: repeat-x;
  5. background-image: -khtml-gradient(linear, left top, right top, from(@startColor), to(@endColor)); // Konqueror
  6. background-image: -moz-linear-gradient(left, @startColor, @endColor); // FF 3.6+
  7. background-image: -ms-linear-gradient(left, @startColor, @endColor); // IE10
  8. background-image: -webkit-gradient(linear, left top, right top, color-stop(0%, @startColor), color-stop(100%, @endColor)); // Safari 4+, Chrome 2+
  9. background-image: -webkit-linear-gradient(left, @startColor, @endColor); // Safari 5.1+, Chrome 10+
  10. background-image: -o-linear-gradient(left, @startColor, @endColor); // Opera 11.10
  11. -ms-filter: %("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)",@startColor,@endColor); // IE8+
  12. filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)",@startColor,@endColor)); // IE6 & IE7
  13. background-image: linear-gradient(left, @startColor, @endColor); // Le standard
  14. }
  15. .vertical (@startColor: #555, @endColor: #333) {
  16. background-color: @endColor;
  17. background-repeat: repeat-x;
  18. background-image: -khtml-gradient(linear, left top, left bottom, from(@startColor), to(@endColor)); // Konqueror
  19. background-image: -moz-linear-gradient(@startColor, @endColor); // FF 3.6+
  20. background-image: -ms-linear-gradient(@startColor, @endColor); // IE10
  21. background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, @startColor), color-stop(100%, @endColor)); // Safari 4+, Chrome 2+
  22. background-image: -webkit-linear-gradient(@startColor, @endColor); // Safari 5.1+, Chrome 10+
  23. background-image: -o-linear-gradient(@startColor, @endColor); // Opera 11.10
  24. -ms-filter: %("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",@startColor,@endColor); // IE8+
  25. filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",@startColor,@endColor)); // IE6 & IE7
  26. background-image: linear-gradient(@startColor, @endColor); // The standard
  27. }
  28. .directional (@startColor: #555, @endColor: #333, @deg: 45deg) {
  29. ...
  30. }
  31. .vertical-three-colors(@startColor: #00b3ee, @midColor: #7a43b6, @colorStop: 0.5, @endColor: #c3325f) {
  32. ...
  33. }
  34. }

Operations and grid system

Get fancy and perform some math to generate flexible and powerful mixins like the one below.

  1. // Griditude
  2. @gridColumns: 16;
  3. @gridColumnWidth: 40px;
  4. @gridGutterWidth: 20px;
  5.  
  6. // Grid System
  7. .container {
  8. width: @siteWidth;
  9. margin: 0 auto;
  10. .clearfix();
  11. }
  12. .columns(@columnSpan: 1) {
  13. display: inline;
  14. float: left;
  15. width: (@gridColumnWidth * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1));
  16. margin-left: @gridGutterWidth;
  17. &:first-child {
  18. margin-left: 0;
  19. }
  20. }
  21. .offset(@columnOffset: 1) {
  22. margin-left: (@gridColumnWidth * @columnOffset) + (@gridGutterWidth * (@columnOffset - 1)) !important;
  23. }

How to leverage this into a theme? Ideas flowwing...

To Posterous, Love Metalab