Bootstrap LESS
Brief introduction
Less is a CSS preprocessor, so CSS dynamic.
On the other hand, Bootstrap is a rapid development of Web App site and toolkit.
In this tutorial, we will discuss the Bootstrap with Less CSS knowledge about the use of. This way, you can use the Less Bootstrap variable, mixed (mixins) and nesting (nesting) in the CSS.
Get Bootstrap and Less CSS
Bootstrap official website: http://getbootstrap.com/
Less official website: http://lesscss.org/
What is included in
Download Bootstrap, unzip the file. Less Bootstrap's components are located under the 'lib' directory. From Bootstrap v1.4.0 version since, it contains nine less files. Here we take a look at what each containing nine files.
bootstrap.less
This is the main Less file. The file import some other less files. The file does not contain any code.
forms.less
Less This file contains the layout of the form, the type of input box style.
mixins.less
This document lets Less CSS code can be reused.
patterns.less
Less This file contains the CSS code duplication of user interface elements will not be located scaffolding Less file basic style overrides.
reset.less
Less This file contains the CSS reset. This is Eric Meyer's CSS reset an update. Some HTML elements such as reset dfn, samp, etc. are exempt.
scaffolding.less
Less This file is saved to create the grid system, structured layout, the basic style that you want the page template.
tables.less
Less This file contains the styles created table.
type.less
Less can be found in this document typography styles. Headings, paragraphs, lists, and other styles of code inside the file is located.
variables.less
This file contains Less Bootstrap to customize the look and feel of variables.
how to use
If you want to use it, include the following code in your HTML page:
<Script src = "js / less-1.1.5.min.js"> </ script>
Please note, less-1.1.5.min.js not js folder, you need to download and put it in the specified folder.
LESS variables and variable values, and usage guidelines
Hyperlink
@linkColor | # 08c | The default link color | |
@linkColorHover | darken(@linkColor, 15%) | The default link color hover |
Gray color
@black | # 000 | |
@grayDarker | # 222 | |
@grayDark | # 333 | |
@gray | # 555 | |
@grayLight | # 999 | |
@grayLighter | #eee | |
@white | #fff |
Accent color
@blue | # 049cdb | |
@green | # 46a546 | |
@red | # 9d261d | |
@yellow | # Ffc40d | |
@orange | # F89406 | |
@pink | # C3325f | |
@purple | # 7a43b6 |
Push button
@primaryButtonBackground | @linkColor |
Form
@placeholderText | @grayLight |
Navigation Bar
@navbarHeight | 40px | |
@navbarBackground | @grayDarker | |
@navbarBackgroundHighlight | @grayDark | |
@navbarText | @grayLight | |
@navbarLinkColor | @grayLight | |
@navbarLinkColorHover | @white |
Status and notification form
@warningText | # C09853 | |
@warningBackground | # F3edd2 | |
@errorText | # B94a48 | |
@errorBackground | # F2dede | |
@successText | # 468847 | |
@successBackground | # Dff0d8 | |
@infoText | # 3a87ad | |
@infoBackground | # D9edf7 |
Bootstrap mixed
The basic mix
The basic mix essentially, is to include the entire or part of the code snippet. Wording similar to a CSS class, you can call anywhere.
.element { .clearfix(); }
Mixed with parameters
Mixing and mixing with basic parameters like, except that the former can receive parameters (by name), the parameters can have default values.
.element { .border-radius(4px); }
Easy to customize
Substantially all of the mixing Bootstrap are stored in mixins.less, this is an excellent tool .less class file, we can mix them in any .less file.
Therefore, the direct use of existing or custom mix a new mix can be.
Comprising mixing
Utilities
mixing | parameter | usage |
---|---|---|
.clearfix() | no | Clear float |
.tab-focus() | no | Similar Webkit gets the focus and style similar to Firefox's outsourcing line |
.center-block() | no | Use margin: auto to automatically centered block-level elements |
.ie7-inline-block() | no | Add Rule display: inline-block to support IE7 |
.size() | @height: 5px, @width: 5px | Quick set the line width and row height |
.square() | @size: 5px | Based on .size() set square area |
.opacity() | @opacity: 100 | Set the percentage of transparency (such as "50" or "75") |
Form
mixing | parameter | usage |
---|---|---|
.placeholder() | @color: @placeholderText | Set the input box placeholder font color |
typesetting
mixing | parameter | usage |
---|---|---|
#font > #family > .serif() | no | Application of an element of a series of serif serif |
#font > #family > .sans-serif() | no | Application of an element of a series of sans-serif fonts |
#font > #family > .monospace() | no | Application of an element of a series of monospace font |
#font > .shorthand() | @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight | Easy to set the font size, weight and line spacing |
#font > .serif() | @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight | Setting serif font family serif, font size, weight and line spacing |
#font > .sans-serif() | @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight | Setting sans-serif font family, font size, weight and line spacing |
#font > .monospace() | @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight | Setting monospace font family, font size, weight and line spacing |
Grid system
mixing | parameter | usage |
---|---|---|
.container-fixed() | no | Create a horizontal center of the container for receiving contents |
#grid > .core() | @gridColumnWidth, @gridGutterWidth | Use n columns and x pixel pitch width to generate a pixel grid system (container, row, column) |
#grid > .fluid() | @fluidGridColumnWidth, @fluidGridGutterWidth | Use n columns and x% pitch width to generate a percentage of the grid system |
CSS3 properties
mixing | parameter | usage |
---|---|---|
.border-radius() | @radius: 5px | Filleting element can be a single value, or may be a value of the four corners |
.box-shadow() | @shadow: 0 1px 3px rgba(0,0,0,.25) | Apply a shadow elements |
.transition() | @transition | Adding CSS3 transition effects (for example, all .2s linear ) |
.rotate() | @degrees | A rotating element of degree n |
.scale() | @ratio | A scaling element n times the original size |
.translate() | @x: 0, @y: 0 | Mobile x and y pixels in the plane |
.background-clip() | @clip | Background clipping an element (for border-radius ) |
.background-size() | @size | CSS3 by changing the background image size |
.box-sizing() | @boxmodel | Change an element box (box) model (for example, with 100% of the width input on the border-box ) |
.user-select() | @select | Change the page of the text selection cursor |
.resizable() | @direction: both | Change the lower right corner coordinates to reset the element size |
.content-columns() | @columnCount, @columnGap: @gridColumnGutter | Let element content using CSS3 columns |
And gradient background
mixing | parameter | usage |
---|---|---|
#translucent > .background() | @color: @white, @alpha: 1 | Setting an element's background color and transparency |
#translucent > .border() | @color: @white, @alpha: 1 | Setting an element's border color and transparency |
#gradient > .vertical() | @startColor, @endColor | Create a cross-browser vertical gradient background |
#gradient > .horizontal() | @startColor, @endColor | Create a cross-browser level gradient background |
#gradient > .directional() | @startColor, @endColor, @deg | Create a cross-browser has a slope gradient background |
#gradient > .vertical-three-colors() | @startColor, @midColor, @colorStop, @endColor | Create a cross-browser tricolor background gradient |
#gradient > .radial() | @innerColor, @outerColor | Create a cross-browser radial gradient background |
#gradient > .striped() | @color, @angle | Create a cross-browser striped background gradient |
#gradientBar() | @primaryColor, @secondaryColor | Button is used to specify a gradient background and shallow dark border |
How to compile
Node.js with the makefile
Run the following command using npm install LESS command-line compiler and uglify-js in the global environment:
$ npm install -g less uglify-js
After successful installation, in the root directory of your Bootstrap run make to compile the CSS.
Also, if you have installed watchr, you can run make watch, so every time you modified Bootstrap, it will automatically recompile Bootstrap. (Must not run, do so just out of convenience.)
Using JavaScript
Simply references less.js file ( download the latest Less.js ) and reload the page.
js file will compile less.
<link rel="stylesheet/less" href="/path/to/bootstrap.less"> <script src="/path/to/less.js"></script>
Command Line
Less if you have installed the command line (Command Line), prototype to compile the following command:
$ lessc ./lib/bootstrap.less > bootstrap.css
If you want to compile a compressed, you can use --compress command.
Less Mac app
Although unofficial, but there is an available Less Mac application can be used to compile.
Click here to download the tutorial to use all the HTML, CSS, JS and image files.