怎么运行的
¥How it works
使用我们的响应式 object-fit
工具类更改 object-fit
属性 的值。此属性告诉内容以多种方式填充父容器,例如保留纵横比或拉伸以占用尽可能多的空间。
¥Change the value of the object-fit
property with our responsive object-fit
utility classes. This property tells the content to fill the parent container in a variety of ways, such as preserving the aspect ratio or stretching to take up as much space as possible.
object-fit
值的类使用 .object-fit-{value}
格式命名。从以下值中选择:
¥Classes for the value of object-fit
are named using the format .object-fit-{value}
. Choose from the following values:
-
contain
-
cover
-
fill
-
scale
(用于缩小)¥
scale
(for scale-down) -
none
示例
¥Examples
将 object-fit-{value}
类添加到 被替换的元素 中:
¥Add the object-fit-{value}
class to the replaced element:
<img src="..." class="object-fit-contain border rounded" alt="...">
<img src="..." class="object-fit-cover border rounded" alt="...">
<img src="..." class="object-fit-fill border rounded" alt="...">
<img src="..." class="object-fit-scale border rounded" alt="...">
<img src="..." class="object-fit-none border rounded" alt="...">
响应式
¥Responsive
对于使用 .object-fit-{breakpoint}-{value}
格式的每个 object-fit
值,也存在响应变化,对于以下断点缩写:sm
、md
、lg
、xl
和 xxl
。可以根据需要组合类以获得各种效果。
¥Responsive variations also exist for each object-fit
value using the format .object-fit-{breakpoint}-{value}
, for the following breakpoint abbreviations: sm
, md
, lg
, xl
, and xxl
. Classes can be combined for various effects as you need.
<img src="..." class="object-fit-sm-contain border rounded" alt="...">
<img src="..." class="object-fit-md-contain border rounded" alt="...">
<img src="..." class="object-fit-lg-contain border rounded" alt="...">
<img src="..." class="object-fit-xl-contain border rounded" alt="...">
<img src="..." class="object-fit-xxl-contain border rounded" alt="...">
视频
¥Video
.object-fit-{value}
和响应式 .object-fit-{breakpoint}-{value}
工具也适用于 <video>
元素。
¥The .object-fit-{value}
and responsive .object-fit-{breakpoint}-{value}
utilities also work on <video>
elements.
<video src="..." class="object-fit-contain" autoplay></video>
<video src="..." class="object-fit-cover" autoplay></video>
<video src="..." class="object-fit-fill" autoplay></video>
<video src="..." class="object-fit-scale" autoplay></video>
<video src="..." class="object-fit-none" autoplay></video>
CSS
Sass 工具 API
¥Sass utilities API
对象拟合工具在 scss/_utilities.scss
中的工具 API 中声明。Learn how to use the utilities API.
¥Object fit utilities are declared in our utilities API in scss/_utilities.scss
. Learn how to use the utilities API.
"object-fit": (
responsive: true,
property: object-fit,
values: (
contain: contain,
cover: cover,
fill: fill,
scale: scale-down,
none: none,
)
),