Components › Components
Demos show your theme.
Aspect ratio
A box that keeps its shape as its width changes.
Usage #
tscl
@import uiAspectRatio from './aspect-ratio.tscl'
<div class="demo">
<uiAspectRatio ratio="16/9">
<img src="/logo.svg" alt="The clarusjs logo, in a 16:9 box" />
</uiAspectRatio>
</div>
<style scoped>
:scope {
display: grid;
gap: 12px;
padding: 24px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-bg);
color: var(--ui-fg);
}
</style>Source #
Copy it next to your components as aspect-ratio.tscl.
tscl
{{-- Aspect ratio: a box that keeps its shape (ratio, '16/9' by default) as its width changes. --}}
@input ratio: string = '16/9'
<div data-part="aspect-ratio" [style]="'aspect-ratio: ' + ratio"><slot /></div>
<style scoped>
@layer theme, base, components, utilities;
@layer components {
:where(:scope) {
position: relative;
width: 100%;
overflow: hidden;
border-radius: var(--ui-radius);
}
:where(:scope > img),
:where(:scope > video),
:where(:scope > iframe) {
width: 100%;
height: 100%;
object-fit: cover;
}
}
</style>Styling #
- On the root:
class,style,id,aria-*anddata-*written on the tag land on its root element;classandstylemerge with its own. - Selectors:
data-partnamesaspect-ratio. - Your rules win: every rule here has zero specificity (
:where()) and sits in@layer components, so your own CSS and Tailwind utilities override it.
Needs #
- theme.css, once per project