使用 CSS 实现固定定位
cssweb developmentfront end technology更新于 2025/8/23 17:16:17
固定定位允许您将元素的位置固定在页面上的特定位置,无论是否滚动。指定的坐标将相对于浏览器窗口。
您可以使用 top 和 left 两个值以及position属性将 HTML 元素移动到 HTML 文档中的任何位置。
- 向左移动 - left 使用负值。
- 向右移动 - left 使用正值。
- 向上移动 - top 使用负值。
- 向下移动 - top 使用正值。
示例
您可以尝试运行以下代码来实现固定定位
<html> <head> </head> <body> <div style = "position:fixed; left:80px; top:20px; background-color:blue;color:white;"> This div has fixed positioning. </div> </body> </html>
相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

