Simplify figure styles and markup

Remove the .figure__container element. According to Tess, putting a <figcaption>
inside a child of a <figure> "doesn't obey the content model" or some shit.
Fiiiiine.

Getting small figures to lay out the way I want them to without the container
was a bit of a trick. Instead of letting the figure span the entire width of the
grid column, let it fit the size of its contents, and then set margin-inline to
auto so it centers.

Doing this also allowed me to remove the .figure--image, etc styles because the
styles and markup are a lot more similar among figures containing different
kinds of elements. Nice!
This commit is contained in:
Eryn Wells 2024-11-25 15:48:04 -08:00
parent 502aa408d9
commit efae2acdea
6 changed files with 44 additions and 56 deletions

View file

@ -68,11 +68,6 @@ hr {
"table" "table"
".codeblock" ".codeblock"
".figure" ".figure"
".figure--main-column"
".figure--code"
".figure--image"
".figure--video"
".figure--youtube"
".highlight" ".highlight"
".instagram-media" ".instagram-media"
) )

View file

@ -98,7 +98,7 @@ body {
gap: var(--space-xl) 0; gap: var(--space-xl) 0;
} }
:is(.list-header, p) { .list-header, p {
grid-column: main-start / main-end; grid-column: main-start / main-end;
} }
@ -110,10 +110,6 @@ body {
grid-column: wide-gutter-start / wide-gutter-end; grid-column: wide-gutter-start / wide-gutter-end;
} }
figure, img {
max-width: 100%;
}
img { img {
object-fit: contain; object-fit: contain;
} }

View file

@ -9,10 +9,22 @@
.figure { .figure {
grid-column: wide-gutter-start / wide-gutter-end; grid-column: wide-gutter-start / wide-gutter-end;
}
.figure--main-column {
grid-column: main-start / main-end;
}
.figure--code {
grid-column: gutter-start / gutter-end;
}
.figure {
display: grid; display: grid;
grid-template-columns: subgrid; grid-template-columns: subgrid;
&:has(> img:only-child, .figure__container:only-child > img:only-child) { &:has(> img:only-child) {
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
@ -37,37 +49,24 @@
} }
.figure--image img, .figure :is(img, video) {
.figure--video video
{
grid-column: wide-gutter-start / wide-gutter-end; grid-column: wide-gutter-start / wide-gutter-end;
width: 100%;
} }
.figure--small { .figure--small {
align-items: center; display: flow;
display: flex; margin-inline: auto;
grid-column: main-start / main-end;
justify-content: center;
min-width: fit-content;
img { img {
max-width: 100%;
width: 480px; width: 480px;
} }
} }
.figure--main-column { .figure video {
grid-column: main-start / main-end;
}
.figure--code {
grid-column: gutter-start / gutter-end;
}
.figure--video video {
width: 100%; width: 100%;
} }

View file

@ -7,8 +7,12 @@
"quarter" ($image.Fit "640x640") "quarter" ($image.Fit "640x640")
-}} -}}
<figure class="figure figure--image {{- $classes := slice "figure" "figure--image" -}}
{{- if eq .size "main" }}figure--main-column{{ end }}"> {{- if eq .size "main" -}}
{{ $classes = $classes | append "figure--main-column" }}
{{- end -}}
<figure class="{{ delimit $classes " " }}">
{{ if .linksToFullSizeImage -}} {{ if .linksToFullSizeImage -}}
<a href="{{ $image.RelPermalink }}"> <a href="{{ $image.RelPermalink }}">
{{- end -}} {{- end -}}

View file

@ -1,8 +1,4 @@
{{- $page := .page -}} {{- $resource := .page.Resources.GetMatch .name -}}
{{- $shouldShowTitle := .shouldShowTitle -}}
{{- $resource := $page.Resources.GetMatch .name -}}
{{- if not $resource }} {{- if not $resource }}
{{ errorf "No resource named '%s'. %s" .name .page.Permalink }} {{ errorf "No resource named '%s'. %s" .name .page.Permalink }}
{{ end -}} {{ end -}}

View file

@ -7,23 +7,21 @@
-}} -}}
<figure class="figure figure--image figure--small"> <figure class="figure figure--image figure--small">
<div class="figure__container"> {{ if .linksToFullSizeImage -}}
{{ if .linksToFullSizeImage -}} <a href="{{ $image.RelPermalink }}">
<a href="{{ $image.RelPermalink }}"> {{- end -}}
{{- end -}} <img
<img src="{{ (index $resizedImages "2x").RelPermalink }}"
src="{{ (index $resizedImages "2x").RelPermalink }}" srcset="
srcset=" {{ (index $resizedImages "2x").RelPermalink }} 960w,
{{ (index $resizedImages "2x").RelPermalink }} 960w, {{ (index $resizedImages "1x").RelPermalink }} 480w,
{{ (index $resizedImages "1x").RelPermalink }} 480w, "
" {{ with $image.Params.alt | default $image.Title }} alt="{{ . }}"{{ end }}
{{ with $image.Params.alt | default $image.Title }} alt="{{ . }}"{{ end }} {{ with $image.Title }} title="{{ . }}"{{ end }}>
{{ with $image.Title }} title="{{ . }}"{{ end }}> {{ if .linksToFullSizeImage -}}
{{ if .linksToFullSizeImage -}} </a>
</a> {{- end -}}
{{- end -}} {{ if .shouldShowTitle }}
{{ if .shouldShowTitle }} {{ partial "page/figures/caption.html" . }}
{{ partial "page/figures/caption.html" . }} {{ end }}
{{ end }}
</div>
</figure> </figure>