- 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 - Flex
- 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 - 位置
本章讨论元素位置的配置。
Bootstrap 提供了一组辅助类来设置页面上元素的位置。Bootstrap 提供的一些类如下:。
.fixed-top
.fixed-bottom
.sticky-top
.sticky-bottom
让我们看看每组类的示例。
固定顶部
类.fixed-top将元素的位置设置在视口的顶部,从边缘到边缘。
这对于创建导航栏或标题很有用,即使用户向下滚动,这些导航栏或标题也会始终显示在屏幕顶部。
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html> <html> <head> <title>Position - Fixed top</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> </head> <body style="height:1500px"> <nav class="navbar navbar-expand-lg text-bg-success navbar-dark fixed-top"> <div class="container-fluid"> <a class="navbar-brand" href="#">Use of .fixed-top class</a> </div> </nav> <div class="container-fluid" style="margin-top:80px"> <h4>Position fixed at top</h4> <p>The class .fixed-top of Bootstrap sets the position of the element at top of the screen.</p> <h1>Scroll down the page to see the position</h1> </div> </body> </html>
固定底部
类.fixed-bottom将元素的位置设置在视口的底部,从边缘到边缘。
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html> <html> <head> <title>Position - Fixed bottom</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> </head> <body style="height:1500px"> <nav class="navbar navbar-expand-lg text-bg-primary navbar-dark fixed-bottom"> <div class="container-fluid"> <a class="navbar-brand" href="#">Use of .fixed-bottom class</a> </div> </nav> <div class="container-fluid" style="margin-top:80px"> <h4>Position fixed at bottom</h4> <p>The class .fixed-bottom of Bootstrap sets the position of the element at the bottom of the page.</p> <h1>Scroll down the page to see the position</h1> </div> </body> </html>
粘性顶部
类.sticky-top用于创建粘性元素,该元素保留在屏幕顶部,从边缘到边缘,但仅在您滚动经过它之后。
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html> <html lang="en"> <head> <title>Position - Sticky top</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> </head> <body style="height:1500px"> <div class="container-fluid mt-3"> <h3>Sticky Navbar</h3> <p>The class <b>.sticky-top</b> is used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.</p> <p>Scroll down the page to see the effect.</p> </div> <nav class="navbar navbar-expand-lg bg-dark navbar-dark sticky-top"> <div class="container-fluid"> <a class="navbar-brand" href="#">Sticky top</a> </div> </nav> <div class="container-fluid"> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> </div> </body> </html>
响应式粘性顶部
响应式粘性顶部类用于网页设计,以创建导航菜单或标题,当用户向下滚动页面时,该菜单或标题会粘贴到屏幕顶部。这确保了导航菜单始终可见且易于访问,即使用户向下移动到页面更下方。
Bootstrap 提供的一些响应式粘性顶部类如下
.sticky-sm-top 将元素(s) 的位置粘贴到小型视口顶部
.sticky-md-top 将元素(s) 的位置粘贴到中等大小的视口顶部
.sticky-lg-top 将元素(s) 的位置粘贴到大型视口顶部
.sticky-xl-top 将元素(s) 的位置粘贴到特大型视口顶部
.sticky-xxl-top 将元素(s) 的位置粘贴到超特大型视口顶部
让我们看一个例子
注意:调整浏览器大小以查看更改。
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html> <html lang="en"> <head> <title>Position - Responsive Sticky top</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> </head> <body style="height:1500px"> <div class="container-fluid mt-3"> <h3>Sticky Navbar</h3> <p>The class <b>.sticky-lg-top</b> is a responsive class, used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.</p> <p>Scroll down the page to see the effect.</p> </div> <nav class="navbar navbar-expand-lg bg-dark navbar-dark sticky-lg-top"> <div class="container-fluid"> <a class="navbar-brand" href="#">Responsive Sticky top</a> </div> </nav> <div class="container-fluid"> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> </div> </body> </html>
粘性底部
类.sticky-bottom用于创建粘性元素,该元素保留在屏幕底部,从边缘到边缘,但仅在您滚动经过它之后。
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html> <html> <head> <title>Position - sticky bottom</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> </head> <body style=height:1000px class="d-flex flex-column"> <!-- Navbar --> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <a class="navbar-brand" href="#">Sticky Bottom Example</a> </div> </nav> <!-- Content --> <div class="container-fluid flex-grow-1"> <h4>sticky bottom</h4> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> </div> <!-- Sticky Footer --> <footer class="footer text-bg-info py-3 sticky-bottom"> <div class="container"> <span class="display-6 text-dark">Sticky bottom</span> </div> </footer> </body> </html>
响应式粘性底部
Bootstrap 提供的一些响应式粘性底部类如下
.sticky-sm-bottom 将元素(s) 的位置粘贴到小型视口底部
.sticky-md-bottom 将元素(s) 的位置粘贴到中等大小的视口底部
.sticky-lg-bottom 将元素(s) 的位置粘贴到大型视口底部
.sticky-xl-bottom 将元素(s) 的位置粘贴到特大型视口底部
.sticky-xxl-bottom 将元素(s) 的位置粘贴到超特大型视口底部
让我们看一个响应式粘性底部类的示例
注意:调整浏览器大小以查看更改。
示例
您可以使用编辑和运行选项编辑并尝试运行此代码。
<!DOCTYPE html> <html> <head> <title>Position - Responsive sticky bottom</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> </head> <body style=height:1000px class="d-flex flex-column"> <!-- Navbar --> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <a class="navbar-brand" href="#">Responsive Sticky Bottom Example</a> </div> </nav> <!-- Content --> <div class="container-fluid flex-grow-1"> <h4>Responsive sticky bottom</h4> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> </div> <!-- Sticky Footer --> <footer class="footer text-bg-warning py-3 sticky-lg-bottom"> <div class="container"> <span class="display-6 text-dark">Sticky bottom</span> </div> </footer> </body> </html>