Susy: How to extend content box to cover grid-padding as well?

前端 未结 1 1582
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 14:42

I just started to play with Susy. I have a 12 column grid that has grid-padding on it. Now i want the header of my page to span the whole grid including the grid-padding. What I

相关标签:
1条回答
  • 2021-02-03 15:18

    You have two good options. One is a simplified version of what you have. Since block elements are 100% width by default, you can simply eliminate your width setting (and all that hacky math).

    header {
        height: 150px;
        margin: 0 0 - $grid-padding;
    }
    

    Your other option is to use multiple containers on the page. That requires a change to the markup, but sometimes it's a simplification that works well. If you move the header outside your current container, and declare it as a container of it's own, that will do the trick.

    (as a side note: if you do need the full width ever, you can simply use the columns-width() function (for inner width, without padding) or container-outer-width() for the full width including the padding.)

    UPDATE:

    I've been using this mixin, to apply bleed anywhere I need it:

    @mixin bleed($padding: $grid-padding, $sides: left right) {
      @if $sides == 'all' {
        margin: - $padding;
        padding: $padding;
      } @else {
        @each $side in $sides {
          margin-#{$side}: - $padding;
          padding-#{$side}: $padding;
        }
      }
    }
    

    Some examples:

    #header { @include bleed; }
    #nav { @include bleed($sides: left); }
    #main { @include bleed($sides: right); }
    #footer { @include bleed(space(3)); }
    
    0 讨论(0)
提交回复
热议问题