【问题标题】:Semantic grid width not being calculated未计算语义网格宽度
【发布时间】:2014-08-12 14:23:14
【问题描述】:

我决定尝试语义网格http://semantic.gs/,因为我真的很喜欢将所有网格逻辑都放在 less 中的概念,而不必像我一直在使用的引导网格中那样向 HTML 添加类最近。

我的问题是我找不到我遇到的问题的文档或参考资料:

我将 import grid.less 放在我的主目录中。

然后在我的 general.less 中定义 .column(12);例如。

问题出在浏览器中:

width: 100%*((((20+60)*12)-20) / (60*12) + (20*12) * 1px); 

当然是无效属性。

就像 less 没有编译那部分,但它肯定在编译,所以我有点卡在这里。以前有没有人遇到过这个问题,任何帮助将不胜感激。


我不得不提到我编译到一个 main.css 然后链接在页面中,我没有在网页中使用 less.js,这是我在他们的网站上看到的例子,但这不应该影响全部,或者是?


代码示例是

main.less(这个文件是使用 grunt 编译成 main.css)

//------------------------------//
//-------------LIBRARIES ------//
//------------------------------//

@import 'less/normalize.less';   
@import 'less/mixins.less';
@import 'less/grid.less';   

//------------------------------//
//-------------GENERAL--------//
//----------------------------// 

@import 'less/variables.less'; 
@import 'less/general.less';    

General.less

header, footer { 
  margin:0;
  overflow:hidden;
  .column(6);
}

grid.less(语义网格系统)

/////////////////
// Semantic.gs // for LESS: http://lesscss.org/
/////////////////

// Defaults which you can freely override
@column-width: 60;
@gutter-width: 20;
@columns: 12;

// Utility variable — you should never need to modify this
@gridsystem-width: (@column-width*@columns) + (@gutter-width*@columns) * 1px;

// Set @total-width to 100% for a fluid layout
@total-width: @gridsystem-width;

// Uncomment these two lines and the star-hack width/margin lines below to enable sub-pixel fix for IE6 & 7. See http://tylertate.com/blog/2012/01/05/subpixel-rounding.html
// @min-width: 960;
// @correction: 0.5 / @min-width * 100 * 1%;

// The micro clearfix http://nicolasgallagher.com/micro-clearfix-hack/
.clearfix() {
    *zoom:1;

    &:before,
    &:after {
        content:"";
        display:table;
    }
    &:after {
        clear:both;
    }
}


//////////
// GRID //
//////////

body {
    width: 100%;
    .clearfix;
}

.row(@columns:@columns) {
    display: block;
    width: @total-width*((@gutter-width + @gridsystem-width)/@gridsystem-width);
    margin: 0 @total-width*(((@gutter-width*.5)/@gridsystem-width)*-1);
    // *width: @total-width*((@gutter-width + @gridsystem-width)/@gridsystem-width)-@correction;
    // *margin: 0 @total-width*(((@gutter-width*.5)/@gridsystem-width)*-1)-@correction;
    .clearfix;
}
.column(@x,@columns:@columns) {
    display: inline;
    float: left;
    width: @total-width*((((@gutter-width+@column-width)*@x)-@gutter-width) / @gridsystem-width);
    margin: 0 @total-width*((@gutter-width*.5)/@gridsystem-width);
    // *width: @total-width*((((@gutter-width+@column-width)*@x)-@gutter-width) / @gridsystem-width)-@correction;
    // *margin: 0 @total-width*((@gutter-width*.5)/@gridsystem-width)-@correction;
}
.push(@offset:1) {
    margin-left: @total-width*(((@gutter-width+@column-width)*@offset) / @gridsystem-width) + @total-width*((@gutter-width*.5)/@gridsystem-width);
}
.pull(@offset:1) {
    margin-right: @total-width*(((@gutter-width+@column-width)*@offset) / @gridsystem-width) + @total-width*((@gutter-width*.5)/@gridsystem-width);
}

输出是

width: 100%*((((20+60)*6)-20) / 100%);

【问题讨论】:

  • 如果你想计算宽度,你不需要使用'calc'属性Calc @ MDN
  • 但这就是语义学的来源,我用它作为非常简单的例子,我不应该修改源吗?应该按预期工作
  • 很遗憾,我无法复制该问题,我可能会检查您的 less 版本?:jsbin.com/gobajupubago/1/edit
  • @mikedidthis strictMaths 不知何故,对该行为的最终解释

标签: css less semantic.gs


【解决方案1】:

终于发现问题了。

grid.less 文件似乎是为与旧的 less 版本一起工作而编写的,如果新的 less 版本没有完全包含在括号中,则它们会忽略数学运算。已修复该问题并按预期工作,希望对遇到此问题的其他人有用。

我想关于维护该网格的说法不太好,无论如何都会尝试一下。

//------------编辑-----------//

似乎严格的数学是问题所在,而不是来源。

正如@seven-phases-max 提到的,在某种程度上,我的环境中默认开启了严格的数学运算。

在我的 grunt-contrib-less 选项中,我有 strictMath: false 但应该是 strictMaths: false

我刚刚修复了该测试并且可以正常工作。感谢您帮助我理解问题。

//---------------------------------------------------//

正确的应该是 strictMath: false in gruntfile strictMaths: false 只是忽略,实际上删除了该行并解决了问题:/

【讨论】:

  • 这是通过--strict-math 选项控制的。即使在较新的 Less 版本中,默认情况下它实际上也是 off。所以这个选项在你的构建环境中的某个地方变成了on
  • @seven-phases-max 我的 grunt-contrib-less 选项是 strictMath: false
  • @seven-phases-max 检查我在答案中的编辑,你是对的
  • 这很奇怪。 grunt-contrib-less 文档将其指定为 strictMath(我查看了它的来源,这似乎是正确的)。我猜它现在是这样工作的,因为strictMaths 实际上没有任何效果,而grunt-contrib-less 下降到默认值(即“关闭/假”)。仍然很神秘为什么明确的strictMath: false 不起作用。
猜你喜欢
  • 1970-01-01
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 2018-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-19
相关资源
最近更新 更多