sdxc

[ @sdxc/u/size ]

max-width

Applies the physical max-width property, for elements whose sizing is genuinely tied to the physical viewport axis.

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

Quick reference

Every documented call, beside the CSS it emits.

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

Examples

Basic example

Use maxWidth(n) to cap an element's physical width, like maxWidth(64) or maxWidth(96):

maxWidth(128)
maxWidth(96)
maxWidth(64)
maxWidth(48)
<div mix={[...]}>
	<div mix={[maxWidth(128), ...]}>maxWidth(128)</div>
	<div mix={[maxWidth(96), ...]}>maxWidth(96)</div>
	<div mix={[maxWidth(64), ...]}>maxWidth(64)</div>
	<div mix={[maxWidth(48), ...]}>maxWidth(48)</div>
</div>

Readable line length

Pass any CSS length as a string, like maxWidth("45ch"), to keep lines of text at a comfortable length:

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 mix={[maxWidth("45ch"), ...]}>
	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>

Applying on a state

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

u.hover(u.maxWidth("full"))

Responsive design

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

u.at("md", u.maxWidth("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:

maxWidth(4)

Signature

u.maxWidth(value: SizeValue)

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