OddSite 4.0.0

Media Blocks & Ratios

[data-media]

scss
[data-media] {
  --column: wide;
  --list-padding--default: 1em;
  align-items: var(--align, start);
  display: grid;
  grid-gap: var(--media-gap, var(--gutter));
  grid-template-areas: var(--reverse-y, 'image' 'content');
  margin: var(--newline) 0;

  &[data-reverse~='vertical'] {
    --reverse-y: 'content' 'image';
  }

  @include tools.above('wide-page') {
    grid-template-areas: var(--reverse-x, 'image content');
    grid-template-columns: fit-content(25%) minmax(
        min-content,
        var(--media-content, 1fr)
      );

    &[data-reverse~='horizontal'] {
      --reverse-x: 'content image';
      grid-template-columns: minmax(min-content, var(--media-content, 1fr)) fit-content(
          25%
        );
    }
  }
}

Media blocks align an image with fluid text. The vertical alignment and image size can be adjusted using html attributes and CSS variables.

.media-image

scss
.media-image {
  grid-area: image;
  justify-self: center;
  max-width: var(--media-max, initial);
  min-width: var(--media-min, initial);
  width: var(--media-size, initial);

  img,
  svg {
    height: auto;
    width: 100%;
  }
}

The image in a media-block accepts variables for min/max and width values

.media-content

scss
.media-content {
  grid-area: content;

  > *:first-child {
    margin-top: 0;
  }

  > *:last-child {
    margin-bottom: 0;
  }
}

Ratios

[data-ratio='parent']

scss
[data-ratio='parent'] {
  --ratio: #{tools.ratio('_widescreen')};
  position: relative;

  &::before {
    content: '';
    display: inline-block;
    height: 0;
    padding-top: calc(100% / var(--ratio, #{tools.ratio('_widescreen')}));
    width: 1px;
  }
}

Ratios are created with a parent wrapper set as relative context.

[data-ratio='child']

scss
[data-ratio='child'] {
  @include tools.position(0);
  @include tools.square(100%);
}

The child element takes on the parent ratio through absolute positioning.