LoginSignup
7
6

More than 5 years have passed since last update.

FLOCSS のコンポーネントを作ってみた

Last updated at Posted at 2017-04-25

2017/04/26追記
GitHubに公開しました。

コンポーネントに含める要素

  • margin, padding(mb10など)
  • flex関連
  • absolute関連
  • clearfix
  • background-image
  • 横スクロールする要素

margin, padding

0pxのpxは不要なのでfor文の外で書いてます。

_space.scss
.mt0 { margin-top: 0 !important; }
.mb0 { margin-bottom: 0 !important; }
.pt0 { padding-top: 0 !important; }
.pb0 { padding-bottom: 0 !important; }

@for $i from 1 through 6 {
    .mt#{$i * 5} { margin-top: 5px * $i !important; }
    .mb#{$i * 5} { margin-bottom: 5px * $i !important; }
    .pt#{$i * 5} { padding-top: 5px * $i !important; }
    .pb#{$i * 5} { padding-bottom: 5px * $i !important; }
}

flex

_flex.scss
.flex {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
}
.flex-center {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
}
.flex-start {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: center;
}
.flex-end {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-end;
    align-items: center;
}
.flex-vertical {
    flex-flow: column;
    align-items: flex-start;
}

absolute

topとbottomは、実際はrelativeになっているdivの余白に合わせて調整することが多いので必要ないかもしれません。

_absolute.scss
.relative {
    position: relative;
}
.absolute {
    position: absolute;
}
.absolute-center {
    width: 100%;
    height: 100%;
    margin: auto;
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
}
.absolute-left {
    position: absolute;
    left: 0;
}
.absolute-left-top {
    position: absolute;
    top: 0;
    left: 0;
}
.absolute-left-bottom {
    position: absolute;
    left: 0;
    bottom: 0;
}
.absolute-right {
    position: absolute;
    right: 0;
}
.absolute-right-top {
    position: absolute;
    top: 0;
    right: 0;
}
.absolute-right-bottom {
    position: absolute;
    right: 0;
    bottom: 0;
}
.absolute-top {
    position: absolute;
    top: 0;
}
.absolute-bottom {
    position: absolute;
    bottom: 0;
}

clearfix

_float.scss
.left {
    float: left;
}
.right {
    float: right;
}
.clearfix:before,
.clearfix:after {
    content: '';
    display: block;
    clear: both;
}

background-image

positionを上書きする可能性があるので、ショートハンドにはしない方がいいと思いました。

_bg-image.scss
.bg-image {
    width: 100%;
    height: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

横スクロール

_scroll.scss
.scroll {
    white-space: nowrap;
    overflow-x: scroll;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}
.scroll-vertical {
    white-space: nowrap;
    overflow-x: hidden;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
}

参考

レイアウト・パーツで使える | Web制作者のためのSassの教科書 - 公式サポートサイト

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6