使用Susy 2对嵌套元素进行适当填充

时间:2014-08-01 18:32:50

标签: susy-sass

我正在尝试使用Susy 2构建一个简单的嵌套布局:一个包含两列(子)的容器,每个子列包含副本和两个嵌套列(孙子)。

我注意到孙子栏目有自己的排水沟,因此他们的内容与他们父母的排水沟不一致。

理想情况下,孙子(及其背景颜色)将扩展到子元素的全宽。

实现这一目标的最佳方法是什么?

要点:https://gist.github.com/andreimoment/2a734aa4a0e99b2866e9

HTML:

<div class="parent">
  <div class="child">
    <p>child 1</p>
    <div class="grandchild">Grandchild 1</div>
    <div class="grandchild last">Grandchild 2</div>
  </div>  
  <div class="child last">child 2</div>  
</div>

SCSS:

@import "compass";
@import "susy";

*, *:before, *:after {
  -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}

$susy: (
  columns: 12,
  column-width: 4em,
  gutters: 1/4,
  math: fluid,
  output: float,
  gutter-position:inside,
  global-box-sizing: border-box,
  debug: (
    image: show,
    color: rgba(200,100,100,.3),
    output: overlay,
    toggle: top right,
  ),
);

.parent {
  @include container();
  @include show-grid(background);
  padding:0;
  @include clearfix;
  }

.child {
  background-color: rgba(100,100,200, 0.5);
  @include span(first 6 of 12);
  &.last {
    @include span(last 6 of 12);
  }
}

.grandchild {
  background-color: rgba(100,100,200, 0.5);
  @include span(first 3 of 6);
  &.last {
    @include span(last 3 of 6);
  }
}

1 个答案:

答案 0 :(得分:2)

使用nest关键字告诉Susy跨区有孩子。只有您正在使用的insidesplit排水沟才需要这样做。

@include span(first 6 of 12 nest);

如果您希望Susy不输出装订线,您也可以使用no-gutters - 但在这种情况下,nest在语义上更明确。

注意:您也不需要将firstinsidesplit排水沟一起使用。你不需要 last,但它可以帮助解决一些亚像素舍入问题。那些没有伤害任何东西,但你可以放弃它们而不会造成伤害。