使用 CSS 预处理器LESS自定义和扩展 Bootstrap ,以利用用于构建 Bootstrap 的 CSS 的变量、mixin 等。
Bootstrap 以 LESS 为核心,这是一种由我们的好朋友Alexis Sellier创建的动态样式表语言。它使开发基于系统的 CSS 更快、更容易、更有趣。
作为 CSS 的扩展,LESS 包括变量、用于可重用代码片段的 mixin、用于简单数学的操作、嵌套,甚至颜色函数。
@linkColor |  
         #08c | 默认链接文本颜色 | |
@linkColorHover |  
         darken(@linkColor, 15%) |  
         默认链接文本悬停颜色 | 
@gridColumns |  
         12 | 
@gridColumnWidth |  
         60像素 | 
@gridGutterWidth |  
         20像素 | 
@fluidGridColumnWidth |  
         6.382978723% | 
@fluidGridGutterWidth |  
         2.127659574% | 
@baseFontSize |  
         13像素 | |
@baseFontFamily |  
         "Helvetica Neue", Helvetica, Arial, sans-serif |  
         |
@baseLineHeight |  
         18像素 | 
@black |  
         #000 | |
@grayDarker |  
         第222章 | |
@grayDark |  
         第333章 | |
@gray |  
         #555 | |
@grayLight |  
         #999 | |
@grayLighter |  
         #eee | |
@white |  
         #fff | 
@blue |  
         #049cdb | |
@green |  
         #46a546 | |
@red |  
         #9d261d | |
@yellow |  
         #ffc40d | |
@orange |  
         #f89406 | |
@pink |  
         #c3325f | |
@purple |  
         #7a43b6 | 
@primaryButtonBackground |  
         @linkColor |  
         
@placeholderText |  
         @grayLight |  
         
@navbarHeight |  
         40像素 | |
@navbarBackground |  
         @grayDarker |  
         |
@navbarBackgroundHighlight |  
         @grayDark |  
         |
@navbarText |  
         @grayLight |  
         |
@navbarLinkColor |  
         @grayLight |  
         |
@navbarLinkColorHover |  
         @white |  
         
@warningText |  
         #f3edd2 | |
@warningBackground |  
         #c09853 | |
@errorText |  
         #b94a48 | |
@errorBackground |  
         #f2dede | |
@successText |  
         #468847 | |
@successBackground |  
         #dff0d8 | |
@infoText |  
         #3a87ad | |
@infoBackground |  
         #d9edf7 | 
基本的 mixin 本质上是 CSS 片段的包含或部分。它们就像 CSS 类一样编写,可以在任何地方调用。
- . 元素{
 - . 清除修复();
 - }
 
参数 mixin 就像一个基本的 mixin,但它也接受带有可选默认值的参数(因此得名)。
- . 元素{
 - . 边框-半径(4px );
 - }
 
几乎所有 Bootstrap 的 mixin 都存储在 mixins.less 中,这是一个很棒的实用 .less 文件,使您可以在工具包中的任何 .less 文件中使用 mixin。
因此,请继续使用现有的,或者根据需要随意添加自己的。
| 米信 | 参数 | 用法 | 
|---|---|---|
.clearfix() |  
       没有任何 | 添加到任何父级以清除其中的浮动 | 
.tab-focus() |  
       没有任何 | 应用 Webkit 焦点样式和圆形 Firefox 轮廓 | 
.center-block() |  
       没有任何 | 使用自动居中块级元素margin: auto |  
      
.ie7-inline-block() |  
       没有任何 | 除了常规使用display: inline-block以获得 IE7 支持 |  
      
.size() |  
       @height: 5px, @width: 5px |  
       快速设置一行的高度和宽度 | 
.square() |  
       @size: 5px |  
       建立在.size()将宽度和高度设置为相同值的基础上 |  
      
.opacity() |  
       @opacity: 100 |  
       以整数形式设置不透明度百分比(例如,“50”或“75”) | 
| 米信 | 参数 | 用法 | 
|---|---|---|
.placeholder() |  
       @color: @placeholderText |  
       设置placeholder输入的文本颜色 |  
      
| 米信 | 参数 | 用法 | 
|---|---|---|
#font > #family > .serif() |  
       没有任何 | 使元素使用衬线字体堆栈 | 
#font > #family > .sans-serif() |  
       没有任何 | 使元素使用无衬线字体堆栈 | 
#font > #family > .monospace() |  
       没有任何 | 使元素使用等宽字体堆栈 | 
#font > .shorthand() |  
       @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight |  
       轻松设置字体大小、粗细和行距 | 
#font > .serif() |  
       @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight |  
       将字体系列设置为衬线,并控制大小、粗细和行距 | 
#font > .sans-serif() |  
       @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight |  
       将字体系列设置为无衬线,并控制大小、粗细和行距 | 
#font > .monospace() |  
       @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight |  
       将字体系列设置为等宽,并控制大小、粗细和行距 | 
| 米信 | 参数 | 用法 | 
|---|---|---|
.container-fixed() |  
       没有任何 | 提供一个固定宽度(用 设置@siteWidth)的容器来保存您的内容 |  
      
.columns() |  
       @columns: 1 |  
       构建一个跨越任意数量列的网格列(默认为 1 列) | 
.offset() |  
       @columns: 1 |  
       使用跨越任意数量列的左边距偏移网格列 | 
.gridColumn() |  
       没有任何 | 使元素像网格列一样浮动 | 
| 米信 | 参数 | 用法 | 
|---|---|---|
.border-radius() |  
       @radius: 5px |  
       圆化元素的角。可以是单个值或四个空格分隔的值 | 
.box-shadow() |  
       @shadow: 0 1px 3px rgba(0,0,0,.25) |  
       给元素添加阴影 | 
.transition() |  
       @transition |  
       添加 CSS3 过渡效果(例如,all .2s linear) |  
      
.rotate() |  
       @degrees |  
       将元素旋转n度 | 
.scale() |  
       @ratio |  
       将元素缩放到原始大小的n倍 | 
.translate() |  
       @x: 0, @y: 0 |  
       在 x 和 y 平面上移动元素 | 
.background-clip() |  
       @clip |  
       裁剪元素的背景(对 有用border-radius) |  
      
.background-size() |  
       @size |  
       通过 CSS3 控制背景图像的大小 | 
.box-sizing() |  
       @boxmodel |  
       更改元素的盒子模型(例如,border-box对于 full-width input) |  
      
.user-select() |  
       @select |  
       控制页面上文本的光标选择 | 
.resizable() |  
       @direction: both |  
       使任何元素在右侧和底部可调整大小 | 
.content-columns() |  
       @columnCount, @columnGap: @gridColumnGutter |  
       使任何元素的内容使用 CSS3 列 | 
| 米信 | 参数 | 用法 | 
|---|---|---|
.#translucent > .background() |  
       @color: @white, @alpha: 1 |  
       给元素一个半透明的背景色 | 
.#translucent > .border() |  
       @color: @white, @alpha: 1 |  
       给元素一个半透明的边框颜色 | 
.#gradient > .vertical() |  
       @startColor, @endColor |  
       创建跨浏览器垂直背景渐变 | 
.#gradient > .horizontal() |  
       @startColor, @endColor |  
       创建跨浏览器水平背景渐变 | 
.#gradient > .directional() |  
       @startColor, @endColor, @deg |  
       创建跨浏览器的定向背景渐变 | 
.#gradient > .vertical-three-colors() |  
       @startColor, @midColor, @colorStop, @endColor |  
       创建跨浏览器三色背景渐变 | 
.#gradient > .radial() |  
       @innerColor, @outerColor |  
       创建跨浏览器径向背景渐变 | 
.#gradient > .striped() |  
       @color, @angle |  
       创建跨浏览器条纹背景渐变 | 
.#gradientBar() |  
       @primaryColor, @secondaryColor |  
       用于按钮分配渐变和稍暗的边框 | 
通过运行以下命令,使用 npm 安装 LESS 命令行编译器:
$ npm 少安装
安装后,只需make从引导目录的根目录运行即可,一切就绪。
此外,如果您安装了watchr,您可能会在make watch每次编辑 bootstrap 库中的文件时自动重建 bootstrap(这不是必需的,只是一种方便的方法)。
通过 Node 安装 LESS 命令行工具并运行以下命令:
$ lessc ./lib/bootstrap.less > bootstrap.css
--compress如果您要保存一些字节,请务必包含在该命令中!
下载最新的 Less.js并在<head>.
<link rel = "stylesheet/less" href = "/path/to/bootstrap.less" > <script src = "/path/to/less.js" ></script>
要重新编译 .less 文件,只需保存它们并重新加载您的页面。Less.js 编译它们并将它们存储在本地存储中。
非官方的 Mac 应用程序会监视 .less 文件的目录,并在每次保存监视的 .less 文件后将代码编译为本地文件。
如果您愿意,您可以在应用程序中切换首选项以自动缩小以及编译文件最终位于哪个目录。
Crunch 是一款外观精美的 LESS 编辑器和编译器,构建于 Adobe Air 之上。
CodeKit 由与非官方 Mac 应用程序相同的人创建,是一个编译 LESS、SASS、Stylus 和 CoffeeScript 的 Mac 应用程序。
用于拖放编译 LESS 文件的 Mac、Linux 和 PC 应用程序。另外,源代码在 GitHub 上。