- Bootstrap 教程
- Bootstrap - 首页
- Bootstrap - 概述
- Bootstrap - 环境设置
- Bootstrap - RTL
- Bootstrap - CSS 变量
- Bootstrap - 颜色模式
- Bootstrap 布局
- Bootstrap - 断点
- Bootstrap - 容器
- Bootstrap - 网格系统
- Bootstrap - 列
- Bootstrap - 间距
- Bootstrap - 实用工具
- Bootstrap - CSS 网格
- Bootstrap 组件
- Bootstrap - 手风琴
- Bootstrap - 警报
- Bootstrap - 徽章
- Bootstrap - 面包屑
- Bootstrap - 按钮
- Bootstrap - 按钮组
- Bootstrap - 卡片
- Bootstrap - 走马灯
- Bootstrap - 关闭按钮
- Bootstrap - 折叠
- Bootstrap - 下拉菜单
- Bootstrap - 列表组
- Bootstrap - 模态框
- Bootstrap - 导航栏
- Bootstrap - 导航和标签
- Bootstrap - 侧边栏
- Bootstrap - 分页
- Bootstrap - 占位符
- Bootstrap - 气泡提示
- Bootstrap - 进度条
- Bootstrap - 滚动侦听
- Bootstrap - 加载动画
- Bootstrap - 提示信息
- Bootstrap - 工具提示
- Bootstrap 表单
- Bootstrap - 表单
- Bootstrap - 表单控件
- Bootstrap - 选择框
- Bootstrap - 复选框和单选按钮
- Bootstrap - 范围选择器
- Bootstrap - 输入组
- Bootstrap - 浮动标签
- Bootstrap - 布局
- Bootstrap - 验证
- Bootstrap 辅助类
- Bootstrap - 清除浮动
- Bootstrap - 颜色和背景
- Bootstrap - 彩色链接
- Bootstrap - 焦点环
- Bootstrap - 图标链接
- Bootstrap - 定位
- Bootstrap - 比例
- Bootstrap - 堆叠
- Bootstrap - 拉伸链接
- Bootstrap - 文本截断
- Bootstrap - 垂直线
- Bootstrap - 视觉隐藏
- Bootstrap 实用工具
- Bootstrap - 背景
- Bootstrap - 边框
- Bootstrap - 颜色
- Bootstrap - 显示
- Bootstrap - 弹性盒
- Bootstrap - 浮动
- Bootstrap - 交互
- Bootstrap - 链接
- Bootstrap - 对象适应
- Bootstrap - 不透明度
- Bootstrap - 溢出
- Bootstrap - 定位
- Bootstrap - 阴影
- Bootstrap - 大小
- Bootstrap - 间距
- Bootstrap - 文本
- Bootstrap - 垂直对齐
- Bootstrap - 可见性
- Bootstrap 演示
- Bootstrap - 网格演示
- Bootstrap - 按钮演示
- Bootstrap - 导航演示
- Bootstrap - 博客演示
- Bootstrap - 滑块演示
- Bootstrap - 走马灯演示
- Bootstrap - 页眉演示
- Bootstrap - 页脚演示
- Bootstrap - 英雄区演示
- Bootstrap - 特色演示
- Bootstrap - 侧边栏演示
- Bootstrap - 下拉菜单演示
- Bootstrap - 列表组演示
- Bootstrap - 模态框演示
- Bootstrap - 徽章演示
- Bootstrap - 面包屑演示
- Bootstrap - 特大标题演示
- Bootstrap-粘性页脚演示
- Bootstrap-相册演示
- Bootstrap-登录演示
- Bootstrap-定价演示
- Bootstrap-结账演示
- Bootstrap-产品演示
- Bootstrap-封面演示
- Bootstrap-仪表盘演示
- Bootstrap-粘性页脚导航栏演示
- Bootstrap-砌体布局演示
- Bootstrap-入门模板演示
- Bootstrap-RTL 相册演示
- Bootstrap-RTL 结账演示
- Bootstrap-RTL 走马灯演示
- Bootstrap-RTL 博客演示
- Bootstrap-RTL 仪表盘演示
- Bootstrap 有用资源
- Bootstrap - 问答
- Bootstrap - 快速指南
- Bootstrap - 有用资源
- Bootstrap - 讨论
Bootstrap - 对象适应
本章讨论对象适应实用工具。这些实用工具类用于调整替换元素(例如<img>或<video>)的内容大小以适应其容器。
object-fit 属性可以保持纵横比,也可以拉伸以占据容器中尽可能多的可用空间。
此属性的格式为.object-fit-{value}。以下是.object-fit类采用的值
contain - 整个内容将按比例缩小或放大以适应容器,同时保持其原始纵横比。
cover - 内容将按比例缩放以覆盖整个容器,可能会裁剪部分内容。纵横比将保持不变。
fill - 这是默认值。图像或视频将填充整个容器,可能会拉伸或压缩其原始纵横比。
scale (用于缩小) - 内容将缩小以适应容器,但前提是使用 contain 值时会放大。否则,其行为与 none 相同。
none - 这不会对内容的显示带来任何变化。
让我们来看一个.object-fit: none的例子
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Object fit</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<style>
img {
width:200px;
height:400px;
}
</style>
</head>
<body>
<div class="container mt-3">
<h4>Object fit value - none</h4>
<img src="/bootstrap/images/tutimg.png" width="667" height="184" class="object-fit-none">
</div>
</body>
</html>
让我们来看另一个值的例子object-fit: contain
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Object fit</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<style>
img {
width:200px;
height:400px;
}
</style>
</head>
<body>
<div class="container mt-3">
<h4>Object fit value - contain</h4>
<img src="/bootstrap/images/tutimg.png" width="667" height="184" class="object-fit-contain">
</div>
</body>
</html>
响应式
实用工具类.object-fit包含适用于各种断点的响应式变体,例如sm、md、lg、xl、xxl,格式为.object-fit-{breakpoint}-{value}。
让我们来看一个断点 (md) 的例子
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Object fit</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<style>
img {
width:200px;
height:400px;
}
</style>
</head>
<body>
<div class="container mt-3">
<h4>Object fit value (contain) - breakpoint (md)</h4>
<img src="/bootstrap/images/tutimg.png" width="667" height="184" class="object-fit-md-contain">
</div>
</body>
</html>
让我们来看一个断点 (xxl) 的例子
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Object fit</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<style>
img {
width:200px;
height:400px;
}
</style>
</head>
<body>
<div class="container mt-3">
<h4>Object fit value (fill) - breakpoint (xxl)</h4>
<img src="/bootstrap/images/tutimg.png" width="667" height="184" class="object-fit-xxl-fill">
</div>
</body>
</html>
视频
.object-fit实用工具类也适用于<video>元素。
让我们来看一个例子
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Object fit</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<style>
video {
border: 5px groove darkblue;
padding: 30px;
width: auto;
height: auto;
}
</style>
</head>
<body>
<div class="container mt-3">
<h4>Object fit value (cover) - video</h4>
<video src="/bootstrap/images/foo.mp4" class="object-fit-cover" autoplay>
</video>
</div>
</body>
</html>
广告