webveuje/csspress/demo/absolute.html
2021-03-23 10:58:10 +08:00

52 lines
1.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
div {
width: 60px;
height: 60px;
}
.box1 {
width: 200px;
height: 200px;
background: yellow;
margin: 20px;
/* position:static */
position: absolute;
}
.box2 {
background: red;
position: absolute;
top: 0px;
left: 0px;
}
</style>
</head>
<body>
<div class="box1">
<div class="box2"></div>
</div>
<p>
<p>这里红色的div是依据 body定位的而不是根据父元素黄色的div 定位,</p>
<p> 加上position static 后也是根据body 定位,</p>
<p>当父元素的Position声明为 absolute 时,红色会依据父级黄色定位,但是会超脱文档流,影响下面的元素</p>
</p>
</body>
</html>