媒體與 SVG
物件適應object-fit
Setting how the content should be resized to fit its container.
Overview
| Class | Declarations |
|---|---|
object-fit:none | object-fit: none;
|
object-contain | object-fit: contain;
|
object-cover | object-fit: cover;
|
object-fill | object-fit: fill;
|
object-scale-down | object-fit: scale-down;
|
object-fit:<value> | object-fit: <value>;
|
Examples
Cover a fixed frame
Use object-cover when media should fill its frame while preserving its aspect ratio.
<img class="w:full aspect-ratio:16/9 object-cover" src="/images/cover.jpg" alt="Cover">Generated CSS
@layer utilities { .object-cover { object-fit: cover }}Contain the full media
Use object-contain when the full image or video must remain visible inside the frame.
<img class="w:full aspect-ratio:1/1 object-contain" src="/images/logo.png" alt="Logo">Disable object fitting
Use object-fit:none when the media should render at its intrinsic size within the content box.
<img class="object-fit:none" src="/images/icon.png" alt="Icon">Apply conditionally
Apply styles based on different states using selectors and conditional queries.
<img class="object-cover:hover object-contain@sm object-fit:none@print" src="/images/photo.jpg" alt="">