Aspect Ratio

Aspect ratio container component.

python 4 params

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

NameTypeDefault
contentstr''
ratiostr'16/9'
custom_classstr''
**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
FilePathNotes
moduledjust.components.components.aspect_ratioSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 1 of this component's classes at line 1081. Override those rules, or the custom properties they read, in a stylesheet loaded after it.