使用 CSS 进行绝对定位
cssweb developmentfront end technology更新于 2025/8/23 16:44:17
具有 position: absolute 的元素定位在相对于屏幕左上角的指定坐标处。
您可以使用两个值 top 和 left以及 position 属性将 HTML 元素移动到 HTML 文档中的任何位置。
- 向左移动 - 使用负值 left
- 向右移动 - 使用正值left
- 向上移动 - 使用负值 top
- 向下移动 - 使用正值顶部。
示例
您可以尝试运行以下代码来实现绝对定位 −
<html> <head> </head> <body> <div style = "position:absolute; left:80px; top:20px; background-color:yellow;"> This div has absolute positioning. </div> </body> </html>
相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

