Susy Grid问题,共有6个项目

时间:2016-11-10 01:10:35

标签: sass susy susy-sass

我遇到了一些问题,跨越了我的12个项目,共有2行6个。

我遇到“艺术家”部分的问题。我不确定我是否应该使用gallery mixin,或者只使用像我这样的其他部分。

http://codepen.io/anon/pen/pNjqzw

HTML:

<html>
  <body>
    <header>
      <div class="container">
        <h1>SMEDC 2017</h1>
      </div>
    </header>

    <div class="container">
      <div class="rooms">
        <h1 class="title">Rooms</h1>
        <div class="room"></div>
        <div class="room"></div>
        <div class="room"></div>
      </div>

      <div class="packages">
        <h1 class="title">Packages</h1>
        <div class="package"></div>
        <div class="package"></div>
        <div class="package"></div>
        <div class="package"></div>
      </div>

      <div class="artists">
        <h1 class="title">Artists</h1>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
        <div class="artist"></div>
      </div>
    </div>

    <footer>
      <div class="test">Powered by Smeazy</div>
    </footer>

  </body>
</html>

SASS:

@import "susy";
$susy: ( columns: 12,
         gutters: 1/4,
         global-box-sizing: border-box,
         debug:(image:show)
       );

// Colours
$color-primary: #38a1d6;
$color-secondary: #16f4d0;
$color-tertiary: #fcee21;
$color-grey: #a1acb5;
$color-grey-light: #dce8ef;
$color-grey-dark: #333;

$default-font: edc_font;

@font-face {
    font-family: 'edc_font';
    src: url('../fonts/lemonmilk-webfont.woff2') format('woff2'), url('f../onts/lemonmilk-webfont.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

%clearfix {
    &:after {
        content: "";
        display: table;
        clear: both;
    }
}

header h1 {
    font-family: $default-font;
    text-align: center;
    font-size: 3.5rem;
    margin: 0;
}

.title {
    font-family: $default-font;
    text-align: center;
    font-size: 3rem;
    margin: 0;
}

.container {
    @include container();
}

header {
    background-color: $color-primary;
    height: auto;
}

.rooms {
    .room {
        @include span (4);
        height: 10rem;
        background: green;
        &:last-child {
            @include span (4 last);
        }
    }
}

.packages {
    .package {
        @include span (3);
        height: 10rem;
        background: red;
        &:last-child {
            @include span (3 last);
        }
    }
}

.artists {
    .artist {
        @include span (2);
        height: 10rem;
        background: pink;
        &:last-child {
            @include span (2 last);
        }
    }
}

footer {
    background-color: $color-grey;
    height: auto;
    font-family: $default-font;
    text-align: center;
    padding: gutter();
}

1 个答案:

答案 0 :(得分:1)

目前的问题是:last-child选择容器中的最后一个元素(艺术家#12),而不是行中的最后一个元素(#6&amp;#12)。 Last-child由DOM树决定,而不是布局。

画廊mixin在这里会很棒。它还使用基于DOM的nth-选择器,但更直接地应用它们。由于容器中的所有艺术家都有h1标题,因此您必须启用nth-of-type选项:

.artist {
    // each item spans 2 columns
    // items are targeted by sibling-position (nth) and type (div)
    @include gallery (2, of-type);
    height:10rem;
    background:pink;
}