Neat grid 中的 max-width 元素创建右边距

max-width element in Neat grid creates right margin

我对 Bourbon Neat 比较陌生,自从最近的更新以来,我有点不知所措。我有一个自定义网格,我已经为其设置了媒体查询。网格中的元素包含一张 500x500 照片及其下方的说明。我的问题是,如果我将包含图像的 div 的最大宽度设置为 500px,则网格向左对齐,并且在宽度大于元素+装订线的右侧产生边距。如果我删除最大宽度,它会完美居中,但包含的 div 会比我不想要的图像更宽。如何将我的 max-width 元素以这些宽度居中?显示:块;和边距:自动什么都不做。

我正在使用 HAML 和 SASS。

HAML:

.video-grid
  .video-section#film-tv
    %span.parallelogram
      %h2.parallelogram-title Film and TV
    .film-tv-videos
      %a{:href => "/hardearth/"}
        .video-slide-wrap
          .video-slide
            .video-slide-img-wrap
              %img.video-slide-img{:src => "/images/500x500/hard-earth.jpg"}
          %p.tiny-caption Teaser for Feature Film
          %h6.video-slide-title The Hard Earth
          %p.video-slide-description Documentary exploring America's relationship to Ukraine
      %a{:href => "/vaselinescreen/"}
        .video-slide-wrap
          .video-slide
            .video-slide-img-wrap
              %img.video-slide-img{:src => "/images/500x500/vaseline-screen.jpg"}
          %p.tiny-caption TV Show
          %h6.video-slide-title Vaseline Screen
          %p.video-slide-description Blur pop visions of what life could be like if we loved things we hate.
      %a{:href => "/videos/patrick"}
        .video-slide-wrap
          .video-slide
            .video-slide-img-wrap
              %img.video-slide-img{:src => "/images/500x500/patrick.jpg"}
          %p.tiny-caption Short Film
          %h6.video-slide-title Patrick Worth Dying For
          %p.video-slide-description Playing foreclosure as it lays.
      %a{:href => "/videos/californiapsych/"}
        .video-slide-wrap
          .video-slide
            .video-slide-img-wrap
              %img.video-slide-img{:src => "/images/500x500/california-psych.jpg"}
          %p.tiny-caption Short Film
          %h6.video-slide-title California Psych
          %p.video-slide-description Transcendental ending to an otherwise rotten country.
      %a{:href => "/videos/badcredit/"}
        .video-slide-wrap
          .video-slide
            .video-slide-img-wrap
              %img.video-slide-img{:src => "/images/500x500/bad-credit.jpg"}
          %p.tiny-caption Short Film
          %h6.video-slide-title Bad Credit Good Moms
          %p.video-slide-description Mom moves out of filmmaker's childhood home.

SASS:

$videos-grid: (
  columns: 4,
  gutter: 30px,
  media: 1660px,
);

$videos-grid-2:(
  columns: 3,
  gutter: 30px,
  media: 1440px,
);

$videos-grid-3: (
  columns: 3,
  gutter: 30px,
  media: 1140px,
);

$videos-grid-4: (
  columns: 2,
  gutter: 30px,
  media: 840px,
);

$videos-grid-5: (
  columns: 2,
  gutter: 30px,
  media: 570px,
);

$videos-grid-6: (
  columns: 1,
  gutter: 0px,
  media: 0px,
);


.video-section
  @include grid-container($videos-grid)
  width: 100%
  padding-bottom: 30px
  position: relative
  margin: 0

.video-slide-wrap
  @include grid-column(1, $videos-grid-6)
  @include grid-media($videos-grid-5)
    @include grid-column(1)
  @include grid-media($videos-grid-4)
    @include grid-column(1)
  @include grid-media($videos-grid-3)
    @include grid-column(1)
  @include grid-media($videos-grid-2)
    @include grid-column(1)
  @include grid-media($videos-grid)
    @include grid-column(1)
  max-width: 500px
  text-align: left
  display: block
  margin: auto

.video-slide
  height: auto
  position: relative
  margin: auto
  color: $black
  overflow: hidden

.video-slide-img-wrap
  display: block
  margin: auto
  height: auto
  width: 100%
  max-width: 500px

.video-slide-img
  display: block
  height: auto
  width: 100%

.video-slide-description
  display: block
  margin: auto
  padding: 5px
  font-size: 0.9em
  line-height: 1.2

.video-slide-title
  display: block
  margin: auto
  text-align: center
  margin-bottom: 5px

.tiny-caption
  font-size: .8em
  font-style: italic

.video-slide-wrap 上的最大宽度:500px:

gap on right

没有在 .video-slide-wrap 上设置最大宽度:

grid elements centered but ugly stuff around image

这是假设您的目标是拥有一系列带图像的蓝色框,这些框会一直增长,直到每个都变成 500 像素,然后停止变大,而是彼此之间的距离越来越远。

首先,我认为你应该将你的 %a{:href => "…"}.video-slide-wrap 组合起来,然后给 .video-slide 蓝色的 background-colormax-width

很难反演整个布局,但这可能看起来像:

%a.video-slide-wrap{:href => "/vaselinescreen/"}
  .video-slide
    img
    text

然后是 sass

.video-slide-wrap
  @include grid-column(1, $videos-grid-6)
  @include grid-media($videos-grid-5)
    @include grid-column(1)
  @include grid-media($videos-grid-4)
    @include grid-column(1)
  @include grid-media($videos-grid-3)
    @include grid-column(1)
  @include grid-media($videos-grid-2)
    @include grid-column(1)
  @include grid-media($videos-grid)
    @include grid-column(1)

.video-slide
  max-width: 500px
  text-align: left
  display: block
  margin: 0 auto
  background: blue;

类似的东西应该可以™工作。