<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
*{
margin: 0;
padding: 0;
list-style: none;
}
div{
width: 1000px;
height: 500px;
margin: auto;
}
li{
width: 100px;
height: 100px;
background-color: #000;
position: absolute;
left: 100px;
top: 100px;
}
ul{
width: 200px;
height: 200px;
background-color: #999;
}
.green{
position: relative;
left: 0px;
top: 0px;
}
</style>
</head>
<body>
<div style="background-color: red;"></div>
<div class="green" style="background-color: green";>
<li></li>
<ul></ul>
</div>
<div style="background-color: blue;"></div>
<div style="background-color: pink;"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.container{
width: 81px;
height: 143px;
border: 1px solid #f00;
position: relative;
}
.container>p{
background-color: rgba(0,0,0,0.7);
color: #fff;
margin: 0;
text-align: center;
line-height: 40px;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<img src="img/1.jpg">
<p>xxxxxxx</p>
</div>
</body>
</html>
- 特别强调
- fixed定位——屏幕定位
- absolute和relative配合使用
- absolute:在文档中的描述有一句:相对于已定位的父级,如果没有已定位的父级直接定位到body
- relative:相对于自身的相对位置,而且原先的位置不会被挤占