useAspectRatio

Responsive
stable

Compute a CSS padding-block-end value that enforces a given aspect ratio on a responsive container. Supports explicit aspect-ratio strings (e.g. "16/9") and falls back to the current viewport ratio when none is given. SSR-safe: returns an empty styles array on the server.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

On the server (SSR), IN_BROWSER is false and window is unavailable. aspectStyles returns [] so the layout collapses to its natural box height. The client rehydrates with the correct padding-block-end on the first reactive access.

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

props
requis
{ aspectRatio?: string | number }
Object carrying an optional aspectRatio value. Accepts a numeric ratio (1.777 for 16:9), a division expression string ("16/9"), or is left undefined to use window.innerWidth / window.innerHeight as the ratio.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

aspectStyles
Array of inline CSS declarations to spread via :style. Contains a single padding-block-end percentage when a valid ratio is resolved, or an empty array during SSR.

Usage

Exemples

Extraits de code prêts à coller.

16:9 video placeholder

vue

Hardcoded square

vue