在开发过程中使用Twitter Bootstrap 3

Pet*_*ras 5 css less twitter-bootstrap twitter-bootstrap-3

这是一个相当广泛的问题,但我真的无法将标题缩小到更多.

我已经下载了Bootstrap 3,我正在variables.less运行时进行自定义grunt watch.每当我对LESS进行更改时,grunt都会将所有内容重新编译到dist目录中,然后将其复制到目标静态目录中.所有这一切都很好,但......

  1. 这真的是预期的做法吗?我应该将Bootstrap源目录移动到其他目录以更有效地工作吗?

  2. 如果我想添加一些自定义的LESS表达,例如"隐藏所有IMG元素时,屏幕@screen-md像素",我怎么就可以访问@screen-md我的自定义的LESS文件?

任何提示都非常感谢,因为我发现文档确实缺乏.

Giu*_*ome 8

我的工作流程类似于Matthew Trow,但我更喜欢导入bootstrap.less文件而不是克隆.

我正在使用bower来更新Bootstrap,所以我的文件夹结构是这样的:

> bower_components
  > bootstrap
  > font-awesome
  > requirejs
  ...
> css
  - project.css
  > less
    - project.less
    - variables.less
Run Code Online (Sandbox Code Playgroud)

project.less看起来像这样:

// Bootstrap framework
@import "../../bower_components/bootstrap/less/bootstrap.less";

// Font-awesome awesomeness
@import "../../bower_components/font-awesome/less/font-awesome.less";

// Project specific stuff
@import "variables.less";
@import "stuff.less";
Run Code Online (Sandbox Code Playgroud)

我在我的内部定义了两个变量并覆盖了bootstrap特定的变量variables.less:

// Override Bootstrap variables
@font-family-sans-serif:  "Lucida Grande","Lucida Sans Unicode",Arial,sans-serif;
@btn-default-border: #bbb;
@brand-primary: #b02b2c;
@link-color: #08c;

// Override Font-Awesome variables (path relative to project.css position)
@fa-font-path: "../bower_components/font-awesome/fonts";

//Map Bootstrap variables to myproject specific names
@my-customname-float-breakpoint: @grid-float-breakpoint;
@theme-color: @brand-primary;

//Project specific variables
@my-favourite-color: rgb(228, 1, 1);
Run Code Online (Sandbox Code Playgroud)

然后我只编译project.less生成一个压缩.css的东西(在例子中还有Font Awesome).

在使用Bootstrap 3更新巨大的变量和类之后,有时我觉得将自定义变量映射到我内部的引导变量更好variables.less,而不是在我的less文件中直接使用Bootstrap.

导入bootstrap.less您可以在任何地方使用任何引导变量.所以,例如:

// Hide all images at a viewport smaller than 992px (aka @screen-md)
@media (max-width: @screen-sm-max) {
    img {
        display: none;
    }
}
Run Code Online (Sandbox Code Playgroud)