【问题标题】:Susy: Push(pre) and Pull(苏西:推(前)和拉(
【发布时间】:2013-10-25 06:06:37
【问题描述】:

以下代码将我的 sidebar-first 放在屏幕左侧的一列。

.has-sidebar-first {
.l-content {
  @include span-columns(15 omega, 16); // Span 15 out of 16 columns.
  @include push(1, 16);  // Push element by adding 1 out of 16 columns of left margin.
}
.l-region--sidebar-first {
  @include span-columns(1, 16); // Span 1 out of 16 columns.
  @include pull(1, 16); // Pull element by adding 15 out of 16 columns of negative left margin.      
}

}

sidebar-first 应该占据第一列,内容应该占据接下来的 15 列。 我将 pull 设置为 1 到 16,但它要么不合适,要么完全消失。

有什么建议吗?

Update1:这是完整的 scss 布局(包括 Eric Meyer(他本人!)的建议)将 sidebar-first 放在页面左侧更远的位置。它似乎与 l-content 的宽度相同。

@import "susy";

// Susy Variables

// Set consistent vertical and horizontal spacing units.
$vert-spacing-unit: 20px;
$horz-spacing-unit: 1em;

// Define Susy grid variables mobile first.
$total-columns: 4;
$column-width: 4em;
$gutter-width: $horz-spacing-unit;
$grid-padding: 5px;

$container-style: magic;
$container-width: 1200px;

// Susy Media Layouts @see http://susy.oddbird.net/guides/reference/#ref-media-layouts
$tab: 44em 12; // At 44em use 12 columns.
$desk: 70em 16; // At 70em use 16 columns.

.l-header,
.l-main,
.l-footer {
  @include container; // Define these elements as the grid containers.
  margin-bottom: $vert-spacing-unit;
}

.l-region--highlighted,
.l-region--help,
.l-region--sidebar-first,
.l-region--sidebar-second {
  margin-bottom: $vert-spacing-unit;
}

@include at-breakpoint($tab) { // At a given Susy Media Layout, use a given amount of columns.
  .l-header,
  .l-main,
  .l-footer {
    @include set-container-width; // Reset only the container width (elements have already been declared as containers).
  }

  .l-branding {
    @include span-columns(4, 12); // Span 4 out of 12 columns.
  }
  .l-region--header{
    @include span-columns(8 omega, 12); // Span the last (omega) 8 columns of 12.
  }
  .l-region--navigation {
    clear: both;
  }

  .has-sidebar-first,
  .has-sidebar-second,
  .has-two-sidebars {
    .l-content {
      @include span-columns(7, 12); // Span 7 out of 12 columns.
      @include push(1, 12);  // Push element by adding 1 out of 12 columns of left margin.
    }
    .l-region--sidebar-first, {
      @include span-columns(1, 12); // Span the 1 columns of 12.
    }
    .l-region--sidebar-second {
      @include span-columns(4 omega, 12); // Span the last (omega) 4 columns of 12.
    }
    .l-region--sidebar-first {
      @include pull(8, 12); // Pull element by adding 8 out of 12 columns of negative left margin.
    }
    .l-region--sidebar-second {
      clear: right;
    }
  }
}

@include at-breakpoint($desk) {
  .l-header,
  .l-main,
  .l-footer {
    @include set-container-width; // Reset only the container width (elements have already been declared as containers).
  }

  .l-branding {
    @include span-columns(6, 16); // Span 6 out of 16 columns.
  }
  .l-region--header{
    @include span-columns(10 omega, 16); // Span the last (omega) 10 columns of 16.
  }

  .has-sidebar-first {
    .l-content {
      @include span-columns(15 omega, 16); // Span 15 out of 16 columns.
    }
    .l-region--sidebar-first {
      @include span-columns(1, 16); // Span 1 out of 16 columns.
    }
  }
  .has-sidebar-second {
    .l-content {
      @include span-columns(12, 16); // Span 12 out of 16 columns.
    }
    .l-region--sidebar-second {
      @include span-columns(4 omega, 16); // Span the last (omega) 4 columns of 16.
      clear: none;
    }
  }

  .has-two-sidebars {
    .l-content {
      @include span-columns(10, 16); // Span 10 out of 16 columns.
      @include push(1, 16);  // Push element by adding 1 out of 16 columns of left margin.
    }
    .l-region--sidebar-first {
      @include span-columns(1, 16); // Span 1 out of 16 columns.
    }
    .l-region--sidebar-second {
      @include span-columns(5, 16); // Span 5 out of 16 columns.
    }
    .l-region--sidebar-first {
      @include pull(11, 16); // Pull element by adding 11 out of 16 columns of negative left margin.
    }
    .l-region--sidebar-second {
      @include omega; // This element spans the last (omega) column.
      clear: none;
    }
  }
}

.has-two-sidebars 工作正常。我只希望在 @include at-breakpoint($desk) 时修复 .has-sidebar-first 。如果设置方式存在固有问题,那么我将不得不更改很多内容,但我希望在没有侧边栏的桌面上查看时简单地更改布局。

谢谢

更新 2 按照添加margin-left: 0;的建议在这里添加。

.has-sidebar-first {
.l-content {
  @include span-columns(15 omega, 16); // Span 15 out of 16 columns.
}
.l-region--sidebar-first {
  @include span-columns(1, 16); // Span 1 out of 16 columns.
  margin-left: 0;
}

}

虽然现在将“侧优先”与正确的列对齐,但它显示在内容下方,如图所示: 其余代码相同。两个侧边栏选项仍然正确显示。 有什么建议吗?

解决方案: 根据 Eric 的建议,我需要清除和先前声明的推拉。所以正确的代码是:

.has-sidebar-first {
.l-content {
  @include span-columns(15 omega, 16); // Span 15 out of 16 columns.
  margin-left: 0;
}
.l-region--sidebar-first {
  @include span-columns(1, 16); // Span 1 out of 16 columns.
  margin-left: 0;
}

谢谢

【问题讨论】:

    标签: layout sass susy-compass


    【解决方案1】:

    摆脱pushpull。两者都不需要。您的 omega 项目向右浮动,另一个项目向左浮动,因此两者都将完美地落入到位,无需任何推/拉帮助。

    更新

    您在 .l-region--sidebar-first 上的一个较小断点处设置了一个拉集,该设置仍在较大断点处应用。您只需在$desk 断点处将margin-left 设置为0

    【讨论】:

    • 感谢 Eric 的回复,感谢您为 Susy 付出的所有时间。我尝试移除推拉,但无法正确显示。我更新了现在包含完整 scss 的问题。有什么可以快速解决的吗?
    • 我添加了 margin-left 0 并更新了问题。谢谢
    • 是的,您的内容仍然有 push,将其推到 12 个以上。您可能还有其他类似的东西,我错过了。关键是:如果您在级联中较早添加内容,如果您仍然不需要它们,则必须稍后删除它们。
    • 我这次在内容中添加了另一个margin-left 0 并全部排序。感谢您的帮助和对我的耐心!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 2019-01-08
    • 2013-01-23
    • 1970-01-01
    相关资源
    最近更新 更多