# 宽高比 · JGuang UI

> 按照指定比例稳定展示图片或媒体内容。

- 页面: https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/aspect-ratio
- 改编自: shadcn/ui 文档 (MIT) @ bc0705384b51252af26dcc65425b216bf5eb063c
- 说明：正文保留英文原文。

> 示例 `aspect-ratio-demo`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/aspect-ratio


## Installation


  

**Command**


  

**Manual**


```text
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
```


### Install the following dependencies:


```bash
npm install @base-ui/react
```


### Copy and paste the following code into your project.


[View complete source: components/ui/aspect-ratio.tsx](/r/jguang-ui/base/aspect-ratio.json)


### Update the import paths to match your project setup.


## Usage

```tsx showLineNumbers
import { AspectRatio } from "@/components/ui/aspect-ratio"
```

```tsx showLineNumbers
<AspectRatio ratio={16 / 9}>
  <Image src="..." alt="Image" className="rounded-md object-cover" />
</AspectRatio>
```

## Square

A square aspect ratio component using the `ratio={1 / 1}` prop. This is useful for displaying images in a square format.


> 示例 `aspect-ratio-square`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/aspect-ratio


## Portrait

A portrait aspect ratio component using the `ratio={9 / 16}` prop. This is useful for displaying images in a portrait format.


> 示例 `aspect-ratio-portrait`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/aspect-ratio


## RTL

To enable RTL support in JGuang UI, see the [RTL configuration guide](/systems/jguang-ui/docs/rtl).


> 示例 `aspect-ratio-rtl`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/aspect-ratio


## API Reference

### AspectRatio

The `AspectRatio` component displays content within a desired ratio.

| Prop        | Type     | Default | Required |
| ----------- | -------- | ------- | -------- |
| `ratio`     | `number` | -       | Yes      |
| `className` | `string` | -       | No       |

For more information, see the [Base UI documentation](https://base-ui.com/react/components/aspect-ratio#api-reference).

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
