为什么这个代码不能编译?

时间:2014-09-02 22:52:40

标签: css less

我已经提取了这条较少的代码,这些代码导致Web应用程序在运行异步任务时编译错误代码。在我最初阅读文档之前,我从来没有写过更少的文章,我似乎无法找到错误的文档。有人知道什么是错的吗? 这是错误:

ParseError: Unrecognised input in /Users/****/Desktop/testmoreless.css on line 4, column 3:
3
4   .core (@gridColumnWidth, @gridGutterWidth) {
5

这是整段代码:

#grid {

  .core (@gridColumnWidth, @gridGutterWidth) {

    .spanX (@index) when (@index > 0) {
      (~".span@{index}") { .span(@index); }
      .spanX(@index - 1);
    }
    .spanX (0) {}

    .offsetX (@index) when (@index > 0) {
      (~".offset@{index}") { .offset(@index); }
      .offsetX(@index - 1);
    }
    .offsetX (0) {}

    .offset (@columns) {
      margin-left: (@gridColumnWidth * @columns) + (@gridGutterWidth * (@columns - 1)) + (@gridGutterWidth * 2);
    }

    .span (@columns) {
      width: (@gridColumnWidth * @columns) + (@gridGutterWidth * (@columns - 1));
    }

    .row {
      margin-left: @gridGutterWidth * -1;
      .clearfix();
    }

    [class*="span"] {
      float: left;
      margin-left: @gridGutterWidth;
    }

    // Set the container width, and override it for fixed navbars in media queries
    .container,
    .navbar-fixed-top .container,
    .navbar-fixed-bottom .container { .span(@gridColumns); }

    // generate .spanX and .offsetX
    .spanX (@gridColumns);
    .offsetX (@gridColumns);

  }

  .fluid (@fluidGridColumnWidth, @fluidGridGutterWidth) {

    .spanX (@index) when (@index > 0) {
      (~"> .span@{index}") { .span(@index); }
      .spanX(@index - 1);
    }
    .spanX (0) {}

    .span (@columns) {
      width: (@fluidGridColumnWidth * @columns) + (@fluidGridGutterWidth * (@columns - 1));
    }

    .row-fluid {
      width: 100%;
      .clearfix();
      > [class*="span"] {
        float: left;
        margin-left: @fluidGridGutterWidth;
      }
      > [class*="span"]:first-child {
        margin-left: 0;
      }

      // generate .spanX
      .spanX (@gridColumns);
    }

  }

  .input(@gridColumnWidth, @gridGutterWidth) {

    .spanX (@index) when (@index > 0) {
      (~"input.span@{index}, textarea.span@{index}, .uneditable-input.span@{index}") { .span(@index); }
      .spanX(@index - 1);
    }
    .spanX (0) {}

    .span(@columns) {
      width: ((@gridColumnWidth) * @columns) + (@gridGutterWidth * (@columns - 1)) - 10;
    }

    input,
    textarea,
    .uneditable-input {
      margin-left: 0; // override margin-left from core grid system
    }

    // generate .spanX
    .spanX (@gridColumns);

  }

}

1 个答案:

答案 0 :(得分:1)

看看这个answer

逐字引述答案:


这是文件最初的内容:

(~".span@{index}") { .span(@index); }

在阅读LESS change log之后,我发现他们改变了语法,所以你现在可以直接使用变量而不需要~hack。所以我将mixin.less更改为:

.span@{index} { .span(@index); }

您还需要更改其他几行,但它们都采用相同的格式。

(~".offset@{index}") { .offset(@index); }更改为→.offset@{index} { .offset(@index); }