<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>绝对定位</title>
<style>
#box1{width:100px; height: 100px;background: red;position: absolute;}
#box2{width:200px; height: 200px;background: blueviolet;}
</style>
</head>
<body>
<div id="box1"></div>
<div id="box2"></div>
</body>
</html>
运行结果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>绝对定位</title>
<style>
/* #box1{width:100px; height: 100px;background: red;position: absolute;}
#box2{width:200px; height: 200px;background: blueviolet;} */
span{width: 100px;height: 100px;background: red;position:absolute;}
</style>
</head>
<body>
<!-- <div id="box1"></div>
<div id="box2"></div> -->
<span>这是一个内联的</span>
</body>
</html>
运行结果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>绝对定位</title>
<style>
/* #box1{width:100px; height: 100px;background: red;position: absolute;}
#box2{width:200px; height: 200px;background: blueviolet;} */
/* span{width: 100px;height: 100px;background: red;position:absolute;} */
div{background: red;position: absolute;}
</style>
</head>
<body>
<!-- <div id="box1"></div>
<div id="box2"></div> -->
<!-- <span>这是一个内联的</span> -->
<div>这是一个快</div>
</body>
</html>
运行结果
来源:CSDN
作者:你知道歌谣吗?
链接:https://blog.csdn.net/weixin_43392489/article/details/103517911