1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <!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>
- #box {
- width: 500px;
- height: 2400px;
- margin: 0 auto;
- position: relative;
- border:1px solid #f00;
- }
- div {
- width: 200px;
- height: 200px;
- font-size: 30px;
- color: #000;
- text-align: center;
- line-height: 200px;
- margin-top: 10px;
- }
- #part1 {
- background: #00f;
- }
- #part2 {
- background: #0ff;
- position: absolute;
- /* position: relative; */
- /* position: fixed; */
- /* position: sticky; */
- /* position: static; */
- top: 100px;
- left: 100px;
- }
- #part3 {
- background: #f0f;
- position: static;
- }
- #part4 {
- background: #ff0;
- }
- #part5 {
- background: #f00;
- }
- #part6 {
- background: #0f0;
- }
- </style>
- </head>
- <body>
- <!--
- 定位:position
- top bottom right left
- 1.sticky 粘性定位 一般用作于吸顶效果 top
- 2.static 静态定位
- 3.fixed 固定定位 脱离文档流 不占位 相对于body进行定位
- 4.relative 相对定位 不脱离文档流 占位 相对于自身进行定位
- 5.absolute 绝对定位
- a.父盒子无定位 相对于祖先元素进行定位 脱离文档流不占位
- b.父盒子有定位 子绝父相 相对于父盒子进行定位 脱离文档流不占位
- -->
- <div id="box">
- <div id="part1">1</div>
- <div id="part2">2</div>
- <div id="part3">3</div>
- <div id="part4">4</div>
- <div id="part5">5</div>
- <div id="part6">6</div>
- <div id="part3">7</div>
- <div id="part4">8</div>
- <div id="part5">9</div>
- <div id="part6">10</div>
- </div>
- </body>
- </html>
|