<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML 绝对定位示例</title>
<style>
.relative {
position: relative;
width: 300px;
height: 200px;
background-color: lightblue;
}
.absolute {
position: absolute;
top: 50px;
left: 50px;
width: 100px;
height: 100px;
background-color: lightcoral;
}
</style>
</head>
<body>
<div class="relative">
<div class="absolute"></div>
</div>
</body>
</html>
相对定位 (.relative):
position: relative;:使元素相对于其正常位置进行定位。绝对定位 (.absolute):
position: absolute;:使元素相对于最近的已定位祖先元素进行定位。如果没有已定位的祖先元素,则相对于 <body> 元素。top: 50px; 和 left: 50px;:将元素的顶部和左边距分别设置为 50px。在这个例子中,.absolute 元素是相对于 .relative 元素进行定位的。
上一篇:空格 html
下一篇:空格html
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站