1.display 使用常用:block、inline、inline-block
div标签 默认是block ,其他标签可以设置display:block成为块,inline-block 行块
2.float使用是时候 ,配置margin 调整位置
3.z-index 使用层级属性
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>
</head>
<style>
#root{
border:red 1px solid;
}
#root:after{
content: "";
clear: both;
overflow: hidden;
display: block;
}
#root2{
border:red 1px solid;
width: 500px;
margin: 0 auto;
}
#root2:after{
content: "";
clear: both;
overflow: hidden;
display: block;
}
#div12{
width: 100px;
height: 100px;
margin: 0 auto;
border: 1px violet solid;
text-align: center;
}
#root:after{
content: "";
clear: both;
overflow: hidden;
display: inline-block;
}
#div1{
width: 100px;
height: 100px;
border: 1px violet solid;
text-align: center;
position: relative;
margin-left: 200px;
float: left;
}
#div2{
width: 50px;
height: 50px;
border: 1px violet solid;
text-align: center;
float: left;
}
#div3{
width: 70px;
height: 70px;
text-align: center;
border: 1px violet solid;
position: absolute;
bottom: 0;
float: left;
}
#div4{
width: 150px;
height: 130px; text-align: center;
float: left;
position: fixed;
bottom: 0;
border: 1px violet solid;
}
</style>
<body>
<div id="root">
<div id="div1">1</div>
<div id="div2">2</div>
<div id="div3">3</div>
<div id="div4">4</div>
</div>
<div id="root2">
<div id="div12">12</div>
</div>
</body>
</html>