Susy:Omega和Responsive Grids

时间:2013-04-08 01:26:25

标签: css sass compass-sass susy-compass

使用Susy时,在行的最后一项上添加“omega”标志以删除其margin-right。例如,假设我们需要在12列网格上布置一些项目:

<div class="item">...</div>
<div class="item">...</div>
<div class="item">I'm the last of the row</div>
<div class="item">...</div>

SCSS:

.item{
  @include span-columns(4);
  @include nth-omega(3n);
}

但我们的网格是响应式的,较小的显示器使用8列网格。问题是omega现在需要显示在2n上,而不是3n

<div class="item">...</div>
<div class="item">I'm the last of the row</div>
<div class="item">...</div>
<div class="item">...</div>

所以我的问题是:对于Susy,您是否需要为每个断点重新定义列,或者是否有某种方法可以一次性定义列宽并让omega自然地落在正确的位置?

如果没有,是否有其他网格系统提供?

2 个答案:

答案 0 :(得分:11)

使用Susy解决您的问题

Susy允许覆盖列数。许多Susy mixins允许 - 每个mixin接受$context参数。

但覆盖上下文的最佳方法是使用at-breakpoint mixin:

// Defining the breakpoints
$mobile-to-medium: 400px;
$medium-to-large:  800px;

// Defining columns
$columns-small:    1;
$columns-medium:   8;
$columns-large:    12;

// Starting with a one-column mobile grid
$total-columns: $columns-small;

// Global styles go here

// Mobile-only styles
@include at-breakpoint($total-columns $mobile-to-medium) {
  // ...
}

// Medium-only styles go here
@include at-breakpoint($mobile-to-medium $columns-medium $medium-to-large) {

  .item{
    @include span-columns(3);
    @include nth-omega(2n); } }

// Large-only styles go here
@include at-breakpoint($medium-to-large $columns-large) {

  .item{
    @include span-columns(4);
    @include nth-omega(3n); } }

Omega假设分层响应:移动样式适用于所有宽度;中等样式适用于中等宽度和大宽度,大样式适用于大宽度。

上述方法不是分层的:移动样式仅适用于移动宽度等。这样您就不必担心在不应该去的地方使用omega。

要使用Omega分层方法,只需删除at-breakpoint次调用中的第三个元素(max-width)。但是你必须申请@include remove-nth-omega()

// Defining the breakpoints
$mobile-to-medium: 400px;
$medium-to-large:  800px;

// Defining columns
$columns-small:    1;
$columns-medium:   8;
$columns-large:    12;

// Starting with a one-column mobile grid
$total-columns: $columns-small;

// Global styles go here

// Medium and large styles go here
@include at-breakpoint($mobile-to-medium $columns-medium) {

  .item{
    @include span-columns(3);
    @include nth-omega(2n); } }

// Large-only styles go here
@include at-breakpoint($medium-to-large $columns-large) {

  .item{
    @include span-columns(4);
    @include remove-nth-omega(2n);
    @include nth-omega(3n); } }

概述无欧米茄的方法

有些SASS网格系统不能使用&#34; omega&#34;参数(不要与Drupal的Omega主题混淆)必须应用于每行的最后一项。相反,除了列宽之外,还提供每个元素的位置(项目从哪一列开始)。

为了实现这一点,使用了另一个CSS定位approach,称为&#34;隔离&#34;。使用这种方法的第一个框架是Zen Grids

Susy还通过其isolateisolate-grid mixins支持此方法。

如果没有提及最新和最先进的SASS网格框架Singularity,这个概述就不会完整。它支持两种定位方法,并且可以扩展以支持将来更多(例如最近flexbox到Compass的added。)

答案 1 :(得分:1)

在您的情况下,您将不得不重新定义新断点中的总列数(上下文)。对于nth-omega,您可以使用@include remove-nth-omega(3n)在显式调用第二个调用之前取消第一个调用,但我认为CSS代码有异味(必须中和属性)所以我建议使用媒体查询拆分避免这样做。

另外,我不知道任何可以自动为你做的框架。