css - 创建一个流动的网格 - 百分比似乎搞砸了

标签 css grid sass fluid

我正在查看骨架框架 (getskeleton.com),但我想要一个流畅的网格系统。我也对这些网格的内部工作原理很感兴趣,所以我决定自己动手。

但是,我遇到了 two.columns 百分比的问题。所有其他列宽都可以正常工作。首先,这是正在发生的事情:

enter image description here

第二行明显有问题,我真的想不通是什么。

我的这个布局的代码如下:

   $max-width: 600px;

   .container {
     @include container($max-width);

     .column, .columns {
       @include columns($max-width);
     }

     .one.column, .one.columns  { width: perc(30px, $max-width); }
     .two.columns               { width: perc(80px, $max-width); }
     .three.columns             { width: perc(130px, $max-width); }
     .four.columns              { width: perc(180px, $max-width); }
     .five.columns              { width: perc(230px, $max-width); }
     .six.columns               { width: perc(280px, $max-width); }
     .seven.columns             { width: perc(330px, $max-width); }
     .eight.columns             { width: perc(380px, $max-width); }
     .nine.columns              { width: perc(430px, $max-width); }
     .ten.columns               { width: perc(480px, $max-width); }
     .eleven.columns            { width: perc(530px, $max-width); }
     .twelve.columns            { width: perc(580px, $max-width); }

这是我使用的混合/函数,不确定这是否重要:

@function perc($width, $container-width) {
  @return percentage($width / $container-width);
}

@mixin container($width)  {
  position: relative; 
  width: $width; 
  margin: 0 auto; 
  padding: 0;
}

@mixin columns($max-width)  {
  float: left;
  display: inline;
  margin: 0 10px;
}

HTML 文件中的代码是:

<% 6.times do %>
  <div class="two columns box"></div>
<% end %>

我想如果百分比的计算有问题,所有的行都会以这样或那样的方式困惑。然而,这只是第二个..如果有人看到这里发生了什么,请赐教?

我将处理后的 CSS 放在 pastebin 上:http://pastebin.com/bxq1a5Ge

提前致谢。

最佳答案

我认为您还需要将利润率转换为百分比。每当一个 div 跨越超过 1 列时,20px 的间距宽度将转换为百分比作为 block 宽度的一部分。这最终会在某些时候出错。

另一种选择是,这是一个舍入问题,因为浏览器无法将百分比值整齐地转换为像素值。

我已经设置了一个基本的 jsfiddle of the issue因为 jsfiddle 支持 SCSS。该示例显示选项 2 是一个不错的选择,但我建议将所有宽度更改为百分比。

关于css - 创建一个流动的网格 - 百分比似乎搞砸了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9559801/

相关文章:

html - 我表格的右边框没有在最后一列的边框处结束

html - Div 里面有图像和文本元素,我希望文本绝对居中在图像的中心

html - Bootstrap 模态窗口列布局

html - 将鼠标悬停在一个列表项上也会影响每个列表项

sass - 如何使用 rollup 从 @material 导入 scss 文件?

html - [HTML][CSS] 包含另外 3 个 div 的 Div 不会居中

html - Chrome 搞乱了网站布局,FF 和 IE 都不错

c# - 使用 XtraGrid Entity Framework 创建主/细节网格

Python Tkinter Tix : How to use ScrolledWindow with grid in Tix NoteBook

css - Z-index 组织策略