Components Layout

Aspect ratio

Reserve a stable frame for rectangular or square media.

Live previewGo + HTML
Landscape study · 16:9

Usage

Choose Ratio from wide, square, or portrait. Supply ImageURL and Alt for a photograph. Without an image, the frame renders a monochrome pattern. Caption is optional.

Register aspect-ratio with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "aspect-ratio", mono.Props{
	"Caption": "Landscape study · 16:9",
	"Ratio":   "wide",
})
Rendered HTML
Rendered HTML
<figure data-mono="aspect-ratio" id="demo-aspect-ratio" class="mu-stack" data-ratio="wide">
  <div class="mu-ratio-frame"></div>
  <figcaption class="mu-muted mu-small">Landscape study · 16:9</figcaption>
</figure>
Go template
Go template
<figure data-mono="aspect-ratio" id="{{.ID}}" class="mu-stack" data-ratio="{{.Ratio}}">
  <div class="mu-ratio-frame">{{with .ImageURL}}<img src="{{.}}" alt="{{$.Alt}}">{{end}}</div>
  {{with .Caption}}<figcaption class="mu-muted mu-small">{{.}}</figcaption>{{end}}
</figure>
Component CSS
Component CSS
[data-mono="aspect-ratio"] { margin:0; }
[data-mono="aspect-ratio"] .mu-ratio-frame { aspect-ratio:16/9; max-width:25rem; width:100%; overflow:hidden; border-radius:.35rem; border:1px solid #333; background:repeating-radial-gradient(ellipse at 50% 100%,#eee 0 5%,#171717 5.2% 10%); }
[data-mono="aspect-ratio"][data-ratio="square"] .mu-ratio-frame { aspect-ratio:1; max-width:15rem; }
[data-mono="aspect-ratio"][data-ratio="portrait"] .mu-ratio-frame { aspect-ratio:3/4; max-width:13rem; }
[data-mono="aspect-ratio"] img { display:block; width:100%; height:100%; object-fit:cover; }
Use the HTML in a static site

Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.

Shared CSS Component CSS

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./aspect-ratio.css">

Copy into your project

Run this command from the Mono checkout. Set -out to the component directory in your application.

Terminal
go run ./cmd/mono-ui add -out ./components aspect-ratio
Example properties (JSON)
example.json
{
  "Caption": "Landscape study · 16:9",
  "Ratio": "wide"
}