sdxc

[ @sdxc/u/size ]

max-height

Applies the physical max-height property, for components whose sizing tracks the physical viewport axis.

import { maxHeight } from "@sdxc/u/size";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.maxHeight("full")css({ maxHeight: "100%" })

Examples

Basic example

Use maxHeight(n) to cap an element's height, and pair it with overflowY("auto") to scroll whatever does not fit:

Margins, padding and sizes in this package follow the writing mode, so a layout written once reads correctly in every language. A card padded on its inline start keeps that padding where a sentence begins, whichever side of the screen that is, and the same holds for a list, a sidebar or a toolbar.

<div mix={[maxHeight(32), is(72), overflowY("auto"), ...]}>
	<p mix={[...]}>
		Margins, padding and sizes in this package follow the writing mode, so a layout written once
		reads correctly in every language. A card padded on its inline start keeps that padding
		where a sentence begins, whichever side of the screen that is, and the same holds for a
		list, a sidebar or a toolbar.
	</p>
</div>

Content shorter than the cap

A maximum only limits: an element shorter than maxHeight(24) keeps its own height, and one asking for more stops at the cap:

height(12)
height(48)
<div mix={[hstack({ gap: 4, align: "start" })]}>
	<div mix={[maxHeight(24), height(12), width(40), ...]}>height(12)</div>
	<div mix={[maxHeight(24), height(48), width(40), ...]}>height(48)</div>
</div>

Applying on a state

Wrap the call in a state utility to scope it to one selector.

u.hover(u.maxHeight("full"))

Responsive design

Wrap the call in a container query to scope it to one width.

u.at("md", u.maxHeight("full"))

Customizing your theme

Customizing spacing

Every numeric step multiplies --ui-spacing, so redefining it rescales every spacing and sizing utility at once:

:root {
	--ui-spacing: 0.25rem;
}

Every call that names the step now reads the new value:

maxHeight(4)

Signature

u.maxHeight(value: SizeValue)

Written by Sergio Xalambrí. Follow @sergiodxa for new packages, or sponsor the work.