| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <!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;
- border: 3px solid #0f0;
- margin: 100px auto;
- /* position: relative; */
- }
- /* 定位:top left bottom right */
- #box div {
- width: 200px;
- height: 200px;
- margin-top: 20px;
- }
- #box1 {
- background: red;
- /* fixed 固定定位 相对于浏览器窗口进行定位 脱离文档里 不占位 滚动时候 位置不动 */
- /* position: fixed;
- top: 100px;
- left: 100px; */
- }
- #box2 {
- background: rgb(72, 255, 0);
- /* 静态定位 static 默认定位 */
- /* position: static; */
- /* sticky 粘性定位 不脱离文档流 一般搭配top使用 相当于相对定位和固定定位 一般用于做吸顶效果 */
- /* position: sticky;
- top: 100px; */
- }
- #box3 {
- background: yellow;
- /* relative 相对定位 相对于自己原来位置进行定位 不脱离文档流 */
- /* position: relative;
- top: 300px;
- left: 500px; */
- /* absolute 绝对定位 脱离文档流
- 父级无定位 相对于整个页面进行定位
- 父级有定位 相对于父级进行定位 子绝父相
- */
- position: absolute;
- top: 320;
- /* z-index: -2; */
- /* left: 500px; */
- }
- #box4 {
- background: purple;
- }
- #box5 {
- background: orange;
- }
- </style>
- </head>
- <body>
- <!-- 定位:控制元素在页面的摆放位置
- position
- -->
- <div id="box">
- <div id="box1"></div>
- <div id="box2"></div>
- <div id="box3"></div>
- <div id="box4"></div>
- <div id="box5"></div>
- </div>
- </body>
- </html>
|