1.浮动代码
<!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>
div{
padding: 0px;
margin: 0px;
margin-top:0px auto;
}
.a{
float: left;
background-color: pink;
width: 150px;
height: 300px;
}
.b{
float: right;
background-color: blue;
width:150px;
height: 300px;
}
.c{
margin:400px auto ;
background-color: aqua;
width:150px auto;
height: 300px;
}
</style>
</head>
<body>
<div class="a">1</div>
<div class="b">2</div>
<div class="c">3</div>
</body>
</html>
2.定位代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Positioning Example</title>
<style>
.relative {
position: relative;
width: 200px;
height: 200px;
background-color: yellow;
}
.absolute {
position: absolute;
top: 50px;
left: 50px;
width: 100px;
height: 100px;
background-color: purple;
}
.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 50px;
height: 50px;
background-color: orange;
}
</style>
</head>
<body>
<div class="relative">
相对定位
<div class="absolute">绝对定位</div>
</div>
<div class="fixed">固定定位</div>
</body>
</html>