【问题标题】:Proper padding for nested elements with Susy 2使用 Susy 2 对嵌套元素进行适当的填充
【发布时间】:2014-08-01 18:32:49
【问题描述】:

我正在尝试使用 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);
  }
}

【问题讨论】:

    标签: susy-sass


    【解决方案1】:

    使用 nest 关键字告诉 Susy 一个 span 有孩子。这只需要 insidesplit 排水沟——您正在使用。

    @include span(first 6 of 12 nest);
    

    您也可以在任何时候希望 Susy 不输出装订线时使用 no-gutters — 但在这种情况下,nest 在语义上更清晰。

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

    【讨论】:

    • 谢谢你,埃里克。鉴于我为子/孙元素使用正确的上下文,我是否正确理解添加“嵌套”会产生大小一致的排水沟?
    • 你说的是我提到的nest关键字,还是我们也提供的nested mixin?我不确定我是否理解这个问题。如果正确使用上下文,即使在嵌套位置,排水沟也应该保持一致。 nest 关键字确保您不会在边缘重复,nested mixin 可以帮助您管理更大块的上下文。
    • 我的意思是嵌套关键字,你回答了我的问题。谢谢!
    • Use the nest keyword to tell Susy that a span has children - 为什么跨度不会有孩子?我仍然怀念“巢”的意义
    • nest 删除父元素上的 insidesplit 排水沟,因此这些排水沟不会被子元素复制。仅当子元素也使用 susy 布置在网格上时才重要。
    猜你喜欢
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2021-01-14
    相关资源
    最近更新 更多