CSS三大定位方式(相对,绝对,固定定位)
【1】相对定位:相对定位是相对于自身而言的定位
<head>
<meta charset="UTF-8">
<style>
#a{
position: relative;
left: 4px;
}
</style>
</head>
<body>
<div style="width: 100px; height: 100px; background-color:#8A2BE2; float:left"></div>
<div id="a" style="width: 100px; height: 100px; background-color:#FFD700; float:left"></div>
</body>
【2】绝对定位:相对于body标签进行定位,也可以理解成相对于浏览器;
<head>
<meta charset="UTF-8">
<style>
#b{
position: absolute;
right: 50px;
top: 200px;
}
</style>
</head>
<body>
<div style="margin-left: 100px; background-color: aquamarine;width: 500px;height: 500px;" >
<div id="b" style="background-color: #8A2BE2;width: 100px;height: 100px;"></div>
<div style="background-color: royalblue;width: 100px;height: 100px;"></div>
</div>
</body>
【3】固定定位:相当于固定在浏览器的某个位置,不会随着进度条的改变而改变位置;而相对定位会随着进度条拖动为改变。
<head>
<meta charset="UTF-8">
<title></title>
<style>
#b{
position: fixed;
right: 10px;
top: 200px;
}
</style>
</head>
<body>
<div style="margin-left: 100px; background-color: aquamarine;width: 500px;height: 500px;" >
<div id="b" style="background-color: #8A2BE2;width: 100px;height: 100px;"></div>
<div style="background-color: royalblue;width: 100px;height: 100px;"></div>
</div>
</body>