Aspect Ratio
Aspect ratio container component.
Preview
16 / 9
Arguments
aspect_ratio(content='<div style="width:320px;height:100%;display:grid;place-items:center;background:hsl(var(--muted));border-radius:var(--radius-md,0.375rem)">16 / 9</div>', ratio='16/9')
Usage
views.py
python
from djust import LiveView
from djust.components import AspectRatio
from django.utils.safestring import mark_safe
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = AspectRatio(content=mark_safe('<div style="width:320px;height:100%;display:grid;place-items:center;background:hsl(var(--muted));border-radius:var(--radius-md,0.375rem)">16 / 9</div>'), ratio='16/9')my_template.html
django
{{ component }}Parameters
| Name | Type | Default |
|---|---|---|
| content | str | '' |
| ratio | str | '16/9' |
| custom_class | str | '' |
| **kwargs | — passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.aspect_ratio | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 1 of this component's classes at line 1081. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |